<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Pracainzynierska: Plik źródłowy src/main.c</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Wygenerowano przez Doxygen 1.5.6 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="main.html"><span>Strona&nbsp;główna</span></a></li>
      <li class="current"><a href="files.html"><span>Pliki</span></a></li>
    </ul>
  </div>
<h1>src/main.c</h1><a href="main_8c.html">Idź do dokumentacji tego pliku.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* ======================================================================</span>
<a name="l00002"></a>00002 <span class="comment"> *  WYBRANE PROBLEMY ALOKACJI ZASOBOW,</span>
<a name="l00003"></a>00003 <span class="comment"> *  Kacper D. Tomzynski</span>
<a name="l00004"></a>00004 <span class="comment"> *</span>
<a name="l00005"></a>00005 <span class="comment"> *  Opiekun pracy:</span>
<a name="l00006"></a>00006 <span class="comment"> *  dr inz. Krzysztof Pienkosz</span>
<a name="l00007"></a>00007 <span class="comment"> *</span>
<a name="l00008"></a>00008 <span class="comment"> *      Wydzial Elektroniki i Technik Informacyjnych Politechniki Warszawskiej</span>
<a name="l00009"></a>00009 <span class="comment"> *  2008</span>
<a name="l00010"></a>00010 <span class="comment"> * ====================================================================== */</span>
<a name="l00011"></a>00011 
<a name="l00012"></a>00012 <span class="comment">/* ======================================================================</span>
<a name="l00013"></a>00013 <span class="comment"> *  biblioteki</span>
<a name="l00014"></a>00014 <span class="comment"> * ====================================================================== */</span>
<a name="l00015"></a>00015 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
<a name="l00016"></a>00016 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
<a name="l00017"></a>00017 <span class="preprocessor">#include &lt;string.h&gt;</span>
<a name="l00018"></a>00018 <span class="preprocessor">#include &lt;time.h&gt;</span>
<a name="l00019"></a>00019 <span class="preprocessor">#include &lt;math.h&gt;</span>
<a name="l00020"></a>00020 <span class="preprocessor">#include "<a class="code" href="main_8h.html">main.h</a>"</span>
<a name="l00021"></a>00021 
<a name="l00022"></a>00022 <span class="comment">/* ======================================================================</span>
<a name="l00023"></a>00023 <span class="comment"> *  stale</span>
<a name="l00024"></a>00024 <span class="comment"> * ====================================================================== */</span>
<a name="l00025"></a>00025 
<a name="l00026"></a>00026 <span class="comment">/* dotyczy funkcji PoprawLambda */</span>
<a name="l00027"></a><a class="code" href="main_8c.html#090b5d90b0350e728a076aeef5b1184b">00027</a> <span class="preprocessor">#define ZNAJDZ_MIN_WIEKSZA 1</span>
<a name="l00028"></a><a class="code" href="main_8c.html#edc0d239bfc447fb9dc15e7a96c0a19d">00028</a> <span class="preprocessor"></span><span class="preprocessor">#define ZNAJDZ_MAX_MNIEJSZA 0</span>
<a name="l00029"></a>00029 <span class="preprocessor"></span>
<a name="l00030"></a>00030 <span class="comment">/* ======================================================================</span>
<a name="l00031"></a>00031 <span class="comment"> *  zmienne</span>
<a name="l00032"></a>00032 <span class="comment"> * ====================================================================== */</span>
<a name="l00033"></a><a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a">00033</a> <span class="keywordtype">int</span> <a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a> = 0; 
<a name="l00039"></a><a class="code" href="main_8c.html#27b9e885fcac85097ba2fe849ef058d3">00039</a> <span class="keywordtype">int</span> <a class="code" href="main_8c.html#27b9e885fcac85097ba2fe849ef058d3">PLIKI_SZCZEGOLOWE</a> = 0;      
<a name="l00041"></a>00041 <span class="comment">/*-- parametry zadania niezmienne --------------------------------------------*/</span>
<a name="l00042"></a>00042 
<a name="l00043"></a><a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337">00043</a> <span class="keywordtype">int</span> <a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>=0;   
<a name="l00044"></a><a class="code" href="main_8c.html#4e1e0e72dd773439e333c84dd762a9c3">00044</a> <span class="keywordtype">int</span> <a class="code" href="main_8c.html#4e1e0e72dd773439e333c84dd762a9c3" title="Maksymalna wielkosc alokacji zasobow.">c</a>=0;   
<a name="l00045"></a><a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85">00045</a> <span class="keywordtype">int</span> <a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>=0;   
<a name="l00048"></a><a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c">00048</a> <span class="keywordtype">int</span>* <a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>;       
<a name="l00049"></a><a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42">00049</a> <span class="keywordtype">int</span>* <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>;       
<a name="l00050"></a><a class="code" href="main_8c.html#18edff6f6f8cc7071adfd9bc826378ef">00050</a> <span class="keywordtype">double</span>* <a class="code" href="main_8c.html#18edff6f6f8cc7071adfd9bc826378ef" title="Wektor bazowych dochodowosci .">v</a>;    
<a name="l00052"></a>00052 <span class="comment">/*-- dynamiczne --------------------------------------------------------------*/</span>
<a name="l00053"></a>00053 
<a name="l00054"></a><a class="code" href="main_8c.html#eb52211fe1c73eb9c9d5568074d3013c">00054</a> <span class="keywordtype">double</span>* <a class="code" href="main_8c.html#eb52211fe1c73eb9c9d5568074d3013c" title="Wektor profitow zredukowanych, tj. .">p_</a>;   
<a name="l00055"></a><a class="code" href="main_8c.html#d3f87c8a272c3442f80fe3a4af4108de">00055</a> <span class="keywordtype">double</span>* <a class="code" href="main_8c.html#d3f87c8a272c3442f80fe3a4af4108de" title="Wektor zredukowanych dochodowosci .">v_</a>;   
<a name="l00058"></a><a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35">00058</a> <span class="keywordtype">int</span>* <a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>;  
<a name="l00075"></a><a class="code" href="main_8c.html#4cba98c6387bd12a0acde1fe002efd63">00075</a> <span class="keywordtype">int</span>* <a class="code" href="main_8c.html#4cba98c6387bd12a0acde1fe002efd63" title="Wektor okresla, ktory w kolejnosci malejacej dochodowosci jest i-ty podmiot. .">ki</a>;  
<a name="l00092"></a><a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909">00092</a> <span class="keywordtype">double</span>* <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>;       
<a name="l00094"></a>00094 <span class="comment">/*-- dane relaksacji ---------------------------------------------------------*/</span>
<a name="l00095"></a>00095 
<a name="l00096"></a><a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af">00096</a> <span class="keywordtype">double</span> <a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a> = 0;      
<a name="l00097"></a><a class="code" href="main_8c.html#58222620d44f880a6aec9b6a7309f4d3">00097</a> <span class="keywordtype">double</span> <a class="code" href="main_8c.html#58222620d44f880a6aec9b6a7309f4d3" title="W kazdej iteracji aktualna wartosc .">lambda_1</a> = 0;    
<a name="l00101"></a><a class="code" href="main_8c.html#d4d5373fa78e7853374abf4cd8ed277d">00101</a> <span class="keywordtype">double</span> <a class="code" href="main_8c.html#d4d5373fa78e7853374abf4cd8ed277d" title="W kazdej iteracji aktualna wartosc .">lambda_2</a> = 0;    
<a name="l00105"></a><a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2">00105</a> <span class="keywordtype">int</span> <a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a> = 1;                              
<a name="l00106"></a><a class="code" href="main_8c.html#262072a74026166e1c7b6bf6f135791b">00106</a> <span class="keywordtype">int</span> <a class="code" href="main_8c.html#262072a74026166e1c7b6bf6f135791b" title="Indeks elementu granicznego (wg nomenklatury i.">i_s</a> = 0;                    
<a name="l00108"></a><a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410">00108</a> <span class="keywordtype">double</span> <a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a>;              
<a name="l00109"></a><a class="code" href="main_8c.html#ba4ddc236971684b95ae11d622e50237">00109</a> <span class="keywordtype">double</span> <a class="code" href="main_8c.html#ba4ddc236971684b95ae11d622e50237" title="Aktualna wartosc C(  ).">aktualneC</a>;       
<a name="l00110"></a><a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90">00110</a> <span class="keywordtype">double</span> <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a>; 
<a name="l00112"></a>00112 <span class="comment">/*-- zbieranie wynikow --------------------------------------------------*/</span>
<a name="l00113"></a>00113 
<a name="l00114"></a><a class="code" href="main_8c.html#7313b89a925c5bcdbf8b28a54018cb6a">00114</a> <span class="keywordtype">int</span> <a class="code" href="main_8c.html#7313b89a925c5bcdbf8b28a54018cb6a">czasStartowy</a>;       
<a name="l00115"></a><a class="code" href="main_8c.html#6ced5c44871ebf39b65910b5726a3de0">00115</a> <span class="keywordtype">int</span> <a class="code" href="main_8c.html#6ced5c44871ebf39b65910b5726a3de0">czasAlgorytmu</a>; 
<a name="l00116"></a><a class="code" href="main_8c.html#2d7e54099b87b9746019dda503574581">00116</a> <span class="keywordtype">int</span> <a class="code" href="main_8c.html#2d7e54099b87b9746019dda503574581">licznikIteracji</a> = 0;        
<a name="l00118"></a><a class="code" href="main_8c.html#e41c8500c68b74939c9beab3ff16990e">00118</a> <span class="preprocessor">#define REL 0</span>
<a name="l00119"></a><a class="code" href="main_8c.html#99a3a311f73faef2c0af730e7f4dd00b">00119</a> <span class="preprocessor"></span><span class="preprocessor">#define GLPK_R 1</span>
<a name="l00120"></a><a class="code" href="main_8c.html#0ac59573db46e3d633836e727f08aa0e">00120</a> <span class="preprocessor"></span><span class="preprocessor">#define GLPK_D 2</span>
<a name="l00121"></a><a class="code" href="main_8c.html#3e4baeb2553d751ae0c007569655a137">00121</a> <span class="preprocessor"></span><span class="preprocessor">#define H1 3</span>
<a name="l00122"></a><a class="code" href="main_8c.html#b5e8a97982062958fb8f58a428df09ee">00122</a> <span class="preprocessor"></span><span class="preprocessor">#define H2 4</span>
<a name="l00123"></a><a class="code" href="main_8c.html#e3ea6c504e916b75b4e44abeffdb8477">00123</a> <span class="preprocessor"></span><span class="preprocessor">#define H2P 5</span>
<a name="l00124"></a><a class="code" href="main_8c.html#13ba4f47dcd4f3e4a0dca6330c1916f2">00124</a> <span class="preprocessor"></span><span class="preprocessor">#define H2B 6</span>
<a name="l00125"></a>00125 <span class="preprocessor"></span>
<a name="l00126"></a><a class="code" href="main_8c.html#29b4c5424b00e8c417f6cd28b91c6246">00126</a> <span class="keywordtype">char</span>* <a class="code" href="main_8c.html#29b4c5424b00e8c417f6cd28b91c6246">nazwy</a>[] = {<span class="stringliteral">"REL "</span>,<span class="stringliteral">"LP_R"</span>, <span class="stringliteral">"LP_D"</span>, <span class="stringliteral">"H1  "</span>, <span class="stringliteral">"H2  "</span>, <span class="stringliteral">"H2P "</span>, <span class="stringliteral">"H2B "</span>};
<a name="l00127"></a><a class="code" href="main_8c.html#2dc32c866ea1d483256f14beab4f0859">00127</a> <span class="keywordtype">int</span> <a class="code" href="main_8c.html#2dc32c866ea1d483256f14beab4f0859">wynikIteracje</a>[7];
<a name="l00128"></a><a class="code" href="main_8c.html#bc046b760068e2015d1f943257ad1c9d">00128</a> <span class="keywordtype">double</span> <a class="code" href="main_8c.html#bc046b760068e2015d1f943257ad1c9d">wynikAlokacja</a>[7];
<a name="l00129"></a><a class="code" href="main_8c.html#b0c1a864c503ead10e2426d29c03fcc5">00129</a> <span class="keywordtype">int</span> <a class="code" href="main_8c.html#b0c1a864c503ead10e2426d29c03fcc5">wynikCzas</a>[7];
<a name="l00130"></a>00130 
<a name="l00131"></a>00131 
<a name="l00132"></a>00132 <span class="comment">/*-- informacje o plikach we-wy ------------------------------------------*/</span>
<a name="l00133"></a>00133 
<a name="l00134"></a><a class="code" href="main_8c.html#e401adba12fa394291ec56e59e8120f4">00134</a> <span class="keywordtype">char</span> <a class="code" href="main_8c.html#e401adba12fa394291ec56e59e8120f4">nazwaPlikuWejsciowego</a>[64];
<a name="l00135"></a><a class="code" href="main_8c.html#e13ce79999caa4f4e3e787ee9a17ec0e">00135</a> <span class="keywordtype">char</span> <a class="code" href="main_8c.html#e13ce79999caa4f4e3e787ee9a17ec0e">nazwaProblemu</a>[64];
<a name="l00136"></a><a class="code" href="main_8c.html#dcbfa19007dff19a1e3a32c137445ea2">00136</a> FILE * <a class="code" href="main_8c.html#dcbfa19007dff19a1e3a32c137445ea2">PlikLogu</a>;
<a name="l00137"></a><a class="code" href="main_8c.html#7c91f2a453eee2b8246c3eb270920175">00137</a> <span class="keywordtype">char</span> <a class="code" href="main_8c.html#7c91f2a453eee2b8246c3eb270920175">dodatkoweInformacje</a>[128];
<a name="l00138"></a>00138 
<a name="l00139"></a>00139 
<a name="l00140"></a>00140 <span class="comment">/* ======================================================================</span>
<a name="l00141"></a>00141 <span class="comment"> * **********************************************************************</span>
<a name="l00142"></a>00142 <span class="comment"> *  FUNKCJE</span>
<a name="l00143"></a>00143 <span class="comment"> *  *********************************************************************</span>
<a name="l00144"></a>00144 <span class="comment"> * ====================================================================== */</span>
<a name="l00145"></a>00145 
<a name="l00146"></a>00146 
<a name="l00147"></a>00147 <span class="comment">/* ======================================================================</span>
<a name="l00148"></a>00148 <span class="comment"> *  WczytajDaneWejsciowe</span>
<a name="l00149"></a>00149 <span class="comment"> * ====================================================================== */</span>
<a name="l00175"></a><a class="code" href="main_8c.html#32d9cda086dbd06f8c1fe3f430611d9a">00175</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#32d9cda086dbd06f8c1fe3f430611d9a" title="Wczytuje dane z pliku.">WczytajDaneWejsciowe</a>(<span class="keywordtype">char</span>* plikWejsciowy)
<a name="l00176"></a>00176 {
<a name="l00177"></a>00177     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l00178"></a>00178         printf (<span class="stringliteral">"---- readInputData(%s) ----\n"</span>,plikWejsciowy);
<a name="l00179"></a>00179     FILE *fp;
<a name="l00180"></a>00180 
<a name="l00181"></a>00181     <span class="keywordflow">if</span> ((fp=fopen(plikWejsciowy, <span class="stringliteral">"r"</span>))==NULL)
<a name="l00182"></a>00182     {
<a name="l00183"></a>00183         printf(<span class="stringliteral">"Nie mozna otworzyc qliku '%s' !\n"</span>,plikWejsciowy);
<a name="l00184"></a>00184         exit(1);
<a name="l00185"></a>00185     }
<a name="l00186"></a>00186     <span class="keywordflow">else</span>
<a name="l00187"></a>00187         (printf(<span class="stringliteral">"Czytanie danych z pliku '%s'...\n"</span>,plikWejsciowy));
<a name="l00188"></a>00188 
<a name="l00189"></a>00189     strcpy(<a class="code" href="main_8c.html#e401adba12fa394291ec56e59e8120f4">nazwaPlikuWejsciowego</a>,plikWejsciowy);
<a name="l00190"></a>00190 
<a name="l00191"></a>00191     fscanf(fp,<span class="stringliteral">"%s"</span>,<a class="code" href="main_8c.html#e13ce79999caa4f4e3e787ee9a17ec0e">nazwaProblemu</a>);
<a name="l00192"></a>00192     fscanf(fp,<span class="stringliteral">"\n\n"</span>);
<a name="l00193"></a>00193     fscanf(fp,<span class="stringliteral">"%u"</span>,&amp;<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>);
<a name="l00194"></a>00194     fscanf(fp,<span class="stringliteral">"\n"</span>);
<a name="l00195"></a>00195     fscanf(fp,<span class="stringliteral">"%u"</span>,&amp;<a class="code" href="main_8c.html#4e1e0e72dd773439e333c84dd762a9c3" title="Maksymalna wielkosc alokacji zasobow.">c</a>);
<a name="l00196"></a>00196     fscanf(fp,<span class="stringliteral">"\n"</span>);
<a name="l00197"></a>00197     fscanf(fp,<span class="stringliteral">"%d"</span>,&amp;<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>);
<a name="l00198"></a>00198     fscanf(fp,<span class="stringliteral">"\n\n"</span>);
<a name="l00199"></a>00199 
<a name="l00200"></a>00200     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l00201"></a>00201         printf(<span class="stringliteral">"Alokacja pamieci...\n"</span>);
<a name="l00202"></a>00202     <a class="code" href="main_8c.html#bbeebdb30d90a79d95cab377a59f62f0" title="Dynamiczny alokator danych.">AlokujPamiec</a>(<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>);
<a name="l00203"></a>00203 
<a name="l00204"></a>00204     <span class="keywordtype">int</span> i = 1;
<a name="l00205"></a>00205     <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l00206"></a>00206         fscanf(fp,<span class="stringliteral">"%u\t%u\n"</span>,<a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>+i,<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>+i);
<a name="l00207"></a>00207     fclose(fp);
<a name="l00208"></a>00208 
<a name="l00209"></a>00209     printf(<span class="stringliteral">"\nWczytano poprawnie problem %s: \nN = %d\nK = %d\nc = %d\n"</span>,<a class="code" href="main_8c.html#e13ce79999caa4f4e3e787ee9a17ec0e">nazwaProblemu</a>,<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>,<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>,<a class="code" href="main_8c.html#4e1e0e72dd773439e333c84dd762a9c3" title="Maksymalna wielkosc alokacji zasobow.">c</a>);
<a name="l00210"></a>00210 
<a name="l00211"></a>00211     <a class="code" href="main_8c.html#86892a380cb93ebd030dba5a6302be06" title="Inicjalizuje czesc wektorow.">InicjujDane</a>();
<a name="l00212"></a>00212 
<a name="l00213"></a>00213     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l00214"></a>00214         printf (<span class="stringliteral">"---- readInputData KONIEC ----\n"</span>);
<a name="l00215"></a>00215 }
<a name="l00216"></a>00216 
<a name="l00217"></a>00217 <span class="comment">/* ======================================================================</span>
<a name="l00218"></a>00218 <span class="comment"> *  AlokujPamiec</span>
<a name="l00219"></a>00219 <span class="comment"> * ====================================================================== */</span>
<a name="l00227"></a><a class="code" href="main_8h.html#80c4e8d2623ecf8dd7f52e97fff4a981">00227</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#bbeebdb30d90a79d95cab377a59f62f0" title="Dynamiczny alokator danych.">AlokujPamiec</a>(<span class="keywordtype">int</span> liczbaElementow)
<a name="l00228"></a>00228 {
<a name="l00229"></a>00229     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l00230"></a>00230         printf(<span class="stringliteral">"---- ALLOC DATA ARRAYS(%d) ---\n"</span>,liczbaElementow);
<a name="l00231"></a>00231     <span class="comment">/* "1+" wektory indeksowane sa od jedynki, dlatego potrzebujemy wiecej miejsca */</span>
<a name="l00232"></a>00232 
<a name="l00233"></a>00233     <span class="keywordtype">int</span> NoE = 1+liczbaElementow;
<a name="l00234"></a>00234     <span class="comment">/* stale */</span>
<a name="l00235"></a>00235     <a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a> = (<span class="keywordtype">int</span> *) malloc(NoE * <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>));
<a name="l00236"></a>00236     <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a> = (<span class="keywordtype">int</span> *) malloc(NoE * <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>));
<a name="l00237"></a>00237     <a class="code" href="main_8c.html#18edff6f6f8cc7071adfd9bc826378ef" title="Wektor bazowych dochodowosci .">v</a> = (<span class="keywordtype">double</span> *) malloc(NoE * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));
<a name="l00238"></a>00238 
<a name="l00239"></a>00239     <span class="comment">/* zmienne w czasie wykonywania programu */</span>
<a name="l00240"></a>00240     <a class="code" href="main_8c.html#eb52211fe1c73eb9c9d5568074d3013c" title="Wektor profitow zredukowanych, tj. .">p_</a> = (<span class="keywordtype">double</span> *) malloc(NoE * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));
<a name="l00241"></a>00241     <a class="code" href="main_8c.html#d3f87c8a272c3442f80fe3a4af4108de" title="Wektor zredukowanych dochodowosci .">v_</a> = (<span class="keywordtype">double</span> *) malloc(NoE * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));
<a name="l00242"></a>00242 
<a name="l00243"></a>00243     <a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a> = (<span class="keywordtype">int</span> *) malloc(NoE * <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>));
<a name="l00244"></a>00244     <a class="code" href="main_8c.html#4cba98c6387bd12a0acde1fe002efd63" title="Wektor okresla, ktory w kolejnosci malejacej dochodowosci jest i-ty podmiot. .">ki</a> = (<span class="keywordtype">int</span> *) malloc(NoE * <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>));
<a name="l00245"></a>00245 
<a name="l00246"></a>00246     <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a> = (<span class="keywordtype">double</span> *) malloc(NoE * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));
<a name="l00247"></a>00247 
<a name="l00248"></a>00248     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l00249"></a>00249         printf(<span class="stringliteral">"---- ALLOC DATA ARRAYS KONIEC. ----\n"</span>);
<a name="l00250"></a>00250 }
<a name="l00251"></a>00251 
<a name="l00252"></a>00252 <span class="comment">/* ======================================================================</span>
<a name="l00253"></a>00253 <span class="comment"> *  CZEKAJ</span>
<a name="l00254"></a>00254 <span class="comment"> * ====================================================================== */</span>
<a name="l00259"></a><a class="code" href="main_8c.html#64eaf90839462ac6338df2ecca303987">00259</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#64eaf90839462ac6338df2ecca303987" title="Funkcja pomocnicza, wstrzymuje dzialanie programu na okreslona liczbe sekund.">Czekaj</a>(<span class="keywordtype">int</span> ileSekund)
<a name="l00260"></a>00260 {
<a name="l00261"></a>00261     time_t start = time(NULL);
<a name="l00262"></a>00262     <span class="keywordflow">while</span>(difftime(time(NULL),start)&lt;ileSekund)
<a name="l00263"></a>00263     {
<a name="l00264"></a>00264         ; <span class="comment">//nic nie rob</span>
<a name="l00265"></a>00265     }
<a name="l00266"></a>00266 }
<a name="l00267"></a>00267 
<a name="l00268"></a>00268 <span class="comment">/* ======================================================================</span>
<a name="l00269"></a>00269 <span class="comment"> *  Czas start</span>
<a name="l00270"></a>00270 <span class="comment"> * ====================================================================== */</span>
<a name="l00275"></a><a class="code" href="main_8c.html#e9284b236f128677657631ae56843cae">00275</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#e9284b236f128677657631ae56843cae" title="Jedna z funkcji do pomiaru czasu. ,,Uruchamia&amp;quot; zegar zapisujac w zmiennej czasStartowy...">CzasStart</a>()
<a name="l00276"></a>00276 {
<a name="l00277"></a>00277     <a class="code" href="main_8c.html#7313b89a925c5bcdbf8b28a54018cb6a">czasStartowy</a> = clock();
<a name="l00278"></a>00278 }
<a name="l00279"></a>00279 
<a name="l00280"></a>00280 <span class="comment">/* ======================================================================</span>
<a name="l00281"></a>00281 <span class="comment"> *  Czas stop</span>
<a name="l00282"></a>00282 <span class="comment"> * ====================================================================== */</span>
<a name="l00287"></a><a class="code" href="main_8c.html#2cc2c7e7811c4a88e4dc3ee60b801508">00287</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#2cc2c7e7811c4a88e4dc3ee60b801508" title="Jedna z funkcji do pomiaru czasu. ,,Uruchamia&amp;quot; zegar zapisujac w zmiennej czasStartowy...">CzasStop</a>()
<a name="l00288"></a>00288 {
<a name="l00289"></a>00289     <a class="code" href="main_8c.html#6ced5c44871ebf39b65910b5726a3de0">czasAlgorytmu</a> = (int)((clock()-<a class="code" href="main_8c.html#7313b89a925c5bcdbf8b28a54018cb6a">czasStartowy</a>)*1E3/CLOCKS_PER_SEC);
<a name="l00290"></a>00290 }
<a name="l00291"></a>00291 
<a name="l00292"></a>00292 <span class="comment">/* ======================================================================</span>
<a name="l00293"></a>00293 <span class="comment"> *  Zapisz wyniki</span>
<a name="l00294"></a>00294 <span class="comment"> * ====================================================================== */</span>
<a name="l00313"></a><a class="code" href="main_8c.html#7ff0e94f5e3c9337353542d81db57104">00313</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#7ff0e94f5e3c9337353542d81db57104" title="Generuje pliki wynikowe dla odpowiednich algorytmow.">ZapiszWyniki</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *nazwaPliku)
<a name="l00314"></a>00314 {
<a name="l00315"></a>00315     FILE *Plik;
<a name="l00316"></a>00316     <span class="keywordflow">if</span> (((Plik=fopen(nazwaPliku, <span class="stringliteral">"w"</span>))==NULL))
<a name="l00317"></a>00317     {
<a name="l00318"></a>00318         printf(<span class="stringliteral">"Nie mozna otworzyc pliku wyjsciowego '%s' do zapisu.\n"</span>,nazwaPliku);
<a name="l00319"></a>00319         exit(1);
<a name="l00320"></a>00320     }
<a name="l00321"></a>00321     <span class="keywordflow">else</span>
<a name="l00322"></a>00322         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l00323"></a>00323             printf(<span class="stringliteral">"\n\nOtwarto plik do zapisu.\n"</span>);
<a name="l00324"></a>00324 
<a name="l00325"></a>00325     fprintf(Plik,<span class="stringliteral">"Dane: %s\n"</span>,<a class="code" href="main_8c.html#e401adba12fa394291ec56e59e8120f4">nazwaPlikuWejsciowego</a>);
<a name="l00326"></a>00326     fprintf(Plik,<span class="stringliteral">"N = %d, c = %d, K = %d\n"</span>,<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>,<a class="code" href="main_8c.html#4e1e0e72dd773439e333c84dd762a9c3" title="Maksymalna wielkosc alokacji zasobow.">c</a>,<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>);
<a name="l00327"></a>00327 
<a name="l00328"></a>00328     fprintf(Plik,<span class="stringliteral">"\nAlgorytm : %s\n"</span>,<a class="code" href="main_8c.html#7c91f2a453eee2b8246c3eb270920175">dodatkoweInformacje</a>);
<a name="l00329"></a>00329 
<a name="l00330"></a>00330     fprintf(Plik,<span class="stringliteral">"\nz = %f\n"</span>,<a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a>);
<a name="l00331"></a>00331     fprintf(Plik,<span class="stringliteral">"czas = %d\n"</span>,<a class="code" href="main_8c.html#6ced5c44871ebf39b65910b5726a3de0">czasAlgorytmu</a>);
<a name="l00332"></a>00332     fprintf(Plik,<span class="stringliteral">"iteracje = %d\n"</span>,<a class="code" href="main_8c.html#2d7e54099b87b9746019dda503574581">licznikIteracji</a>);
<a name="l00333"></a>00333     fprintf(Plik,<span class="stringliteral">"\nRozwiazanie:\n"</span>);
<a name="l00334"></a>00334     <span class="keywordtype">int</span> i;
<a name="l00335"></a>00335     <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l00336"></a>00336         fprintf(Plik,<span class="stringliteral">"x[%d] = %f\n"</span>,i,<a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[i]);
<a name="l00337"></a>00337 }
<a name="l00338"></a>00338 
<a name="l00339"></a>00339 
<a name="l00340"></a>00340 <span class="comment">/* ======================================================================</span>
<a name="l00341"></a>00341 <span class="comment"> *  WYNIKI ZBIORCZE</span>
<a name="l00342"></a>00342 <span class="comment"> * ====================================================================== */</span>
<a name="l00347"></a><a class="code" href="main_8c.html#4d5ab92e3f4f9bd0a4f07ecb43764b6e">00347</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#4d5ab92e3f4f9bd0a4f07ecb43764b6e" title="Przedstawia.">AnalizujDane</a>()
<a name="l00348"></a>00348 {
<a name="l00349"></a>00349         <span class="keywordtype">int</span> i = 1;
<a name="l00350"></a>00350         <span class="keywordtype">long</span> suma_wag = 0, suma_profitow = 0;
<a name="l00351"></a>00351 
<a name="l00352"></a>00352         <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++) {
<a name="l00353"></a>00353                 suma_wag += <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[i];
<a name="l00354"></a>00354                 suma_profitow += <a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[i];
<a name="l00355"></a>00355         }
<a name="l00356"></a>00356 
<a name="l00357"></a>00357         <span class="keywordtype">double</span> srednia_waga;
<a name="l00358"></a>00358         srednia_waga = suma_wag / <a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>;
<a name="l00359"></a>00359         printf(<span class="stringliteral">"srednia waga = %f\n"</span>,srednia_waga);
<a name="l00360"></a>00360         printf(<span class="stringliteral">"c / srednia waga = %f\n"</span>,<a class="code" href="main_8c.html#4e1e0e72dd773439e333c84dd762a9c3" title="Maksymalna wielkosc alokacji zasobow.">c</a>/srednia_waga);
<a name="l00361"></a>00361 
<a name="l00362"></a>00362 }
<a name="l00363"></a>00363 
<a name="l00364"></a>00364 
<a name="l00365"></a>00365 
<a name="l00366"></a>00366 <span class="comment">/* ======================================================================</span>
<a name="l00367"></a>00367 <span class="comment"> *  WYNIKI ZBIORCZE</span>
<a name="l00368"></a>00368 <span class="comment"> * ====================================================================== */</span>
<a name="l00373"></a><a class="code" href="main_8c.html#8bd72ae940fe946b5943662c5c41fd7a">00373</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#8bd72ae940fe946b5943662c5c41fd7a" title="Generuje plik z rozwiazaniem zbiorczym dla wielu algorytmow.">WynikiZbiorcze</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *nazwaPliku)
<a name="l00374"></a>00374 {
<a name="l00375"></a>00375     FILE *Plik;
<a name="l00376"></a>00376     <span class="keywordflow">if</span> (((Plik=fopen(nazwaPliku, <span class="stringliteral">"w"</span>))==NULL))
<a name="l00377"></a>00377     {
<a name="l00378"></a>00378         printf(<span class="stringliteral">"Nie mozna otworzyc pliku wyjsciowego '%s' do zapisu.\n"</span>,nazwaPliku);
<a name="l00379"></a>00379         exit(1);
<a name="l00380"></a>00380     }
<a name="l00381"></a>00381     <span class="keywordflow">else</span>
<a name="l00382"></a>00382         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l00383"></a>00383             printf(<span class="stringliteral">"\n\nOtwarto plik do zapisu.\n"</span>);
<a name="l00384"></a>00384 
<a name="l00385"></a>00385 
<a name="l00386"></a>00386     fprintf(Plik,<span class="stringliteral">"Problem: %s\n"</span>,<a class="code" href="main_8c.html#e13ce79999caa4f4e3e787ee9a17ec0e">nazwaProblemu</a>);
<a name="l00387"></a>00387     fprintf(Plik,<span class="stringliteral">"N = %d, c = %d, K = %d\n"</span>,<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>,<a class="code" href="main_8c.html#4e1e0e72dd773439e333c84dd762a9c3" title="Maksymalna wielkosc alokacji zasobow.">c</a>,<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>);
<a name="l00388"></a>00388 
<a name="l00389"></a>00389     <span class="keywordtype">int</span> i=0;
<a name="l00390"></a>00390     fprintf(Plik,<span class="stringliteral">"\n\nALG\t\t\tZ\t\t\tCZAS\tITERACJE\n"</span>);
<a name="l00391"></a>00391     <span class="keywordflow">for</span>(i=0;i&lt;=50;i++)
<a name="l00392"></a>00392         fprintf(Plik,<span class="stringliteral">"-"</span>);
<a name="l00393"></a>00393     <span class="keywordflow">for</span> (i=0; i&lt;7; i++)
<a name="l00394"></a>00394         fprintf(Plik,<span class="stringliteral">"\n%s\t\t%f\t%d\t\t%d"</span>,<a class="code" href="main_8c.html#29b4c5424b00e8c417f6cd28b91c6246">nazwy</a>[i],<a class="code" href="main_8c.html#bc046b760068e2015d1f943257ad1c9d">wynikAlokacja</a>[i],<a class="code" href="main_8c.html#b0c1a864c503ead10e2426d29c03fcc5">wynikCzas</a>[i],<a class="code" href="main_8c.html#2dc32c866ea1d483256f14beab4f0859">wynikIteracje</a>[i]);
<a name="l00395"></a>00395 
<a name="l00396"></a>00396     fprintf(Plik,<span class="stringliteral">"\n\nDANE WEJSCIOWE:\n"</span>);
<a name="l00397"></a>00397     <span class="keywordflow">for</span> (i=0;i&lt;=20; i++)
<a name="l00398"></a>00398         fprintf(Plik,<span class="stringliteral">"-"</span>);
<a name="l00399"></a>00399     fprintf(Plik,<span class="stringliteral">"\ni\tp\tw\n"</span>);
<a name="l00400"></a>00400     <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l00401"></a>00401         fprintf(Plik,<span class="stringliteral">"%d\t%d\t%d\n"</span>,i,<a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[i],<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[i]);
<a name="l00402"></a>00402 
<a name="l00403"></a>00403     fclose(Plik);
<a name="l00404"></a>00404 }
<a name="l00405"></a>00405 
<a name="l00406"></a>00406 
<a name="l00407"></a>00407 
<a name="l00408"></a>00408 <span class="comment">/* ======================================================================</span>
<a name="l00409"></a>00409 <span class="comment"> *  InicjujDane</span>
<a name="l00410"></a>00410 <span class="comment"> * ====================================================================== */</span>
<a name="l00426"></a><a class="code" href="main_8h.html#86892a380cb93ebd030dba5a6302be06">00426</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#86892a380cb93ebd030dba5a6302be06" title="Inicjalizuje czesc wektorow.">InicjujDane</a>()
<a name="l00427"></a>00427 {
<a name="l00428"></a>00428     <span class="keywordtype">int</span> i;
<a name="l00429"></a>00429     <a class="code" href="main_8c.html#2d7e54099b87b9746019dda503574581">licznikIteracji</a> = 0;
<a name="l00430"></a>00430 
<a name="l00431"></a>00431     <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l00432"></a>00432     {
<a name="l00433"></a>00433         <a class="code" href="main_8c.html#eb52211fe1c73eb9c9d5568074d3013c" title="Wektor profitow zredukowanych, tj. .">p_</a>[i] = <a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[i];
<a name="l00434"></a>00434         <a class="code" href="main_8c.html#18edff6f6f8cc7071adfd9bc826378ef" title="Wektor bazowych dochodowosci .">v</a>[i] = (double)<a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[i]/<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[i];
<a name="l00435"></a>00435         <a class="code" href="main_8c.html#d3f87c8a272c3442f80fe3a4af4108de" title="Wektor zredukowanych dochodowosci .">v_</a>[i] = <a class="code" href="main_8c.html#18edff6f6f8cc7071adfd9bc826378ef" title="Wektor bazowych dochodowosci .">v</a>[i];
<a name="l00436"></a>00436         <a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[i] = i;
<a name="l00437"></a>00437         <a class="code" href="main_8c.html#4cba98c6387bd12a0acde1fe002efd63" title="Wektor okresla, ktory w kolejnosci malejacej dochodowosci jest i-ty podmiot. .">ki</a>[i] = i;
<a name="l00438"></a>00438         <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[i] = 0;
<a name="l00439"></a>00439     }
<a name="l00440"></a>00440 
<a name="l00441"></a>00441     <a class="code" href="main_8c.html#6e789198fc2fe0924eda2fd9034f520e">Sortuj</a>();
<a name="l00442"></a>00442 }
<a name="l00443"></a>00443 
<a name="l00444"></a>00444 <span class="comment">/* ======================================================================</span>
<a name="l00445"></a>00445 <span class="comment"> *  qSort</span>
<a name="l00446"></a>00446 <span class="comment"> * ====================================================================== */</span>
<a name="l00453"></a><a class="code" href="main_8c.html#316b792d3515c55086527d4a6aa7a386">00453</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#316b792d3515c55086527d4a6aa7a386">qSort</a>(<span class="keywordtype">int</span> Lo, <span class="keywordtype">int</span> Hi)
<a name="l00454"></a>00454 {
<a name="l00455"></a>00455     <span class="keywordtype">int</span> i,j;
<a name="l00456"></a>00456     <span class="keywordtype">double</span> x;
<a name="l00457"></a>00457 
<a name="l00458"></a>00458     <span class="keywordtype">int</span> midIndex = <a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[(Lo+Hi)/2];
<a name="l00459"></a>00459 
<a name="l00460"></a>00460     x = <a class="code" href="main_8c.html#d3f87c8a272c3442f80fe3a4af4108de" title="Wektor zredukowanych dochodowosci .">v_</a>[midIndex];
<a name="l00461"></a>00461 
<a name="l00462"></a>00462     i = Lo;
<a name="l00463"></a>00463     j = Hi;
<a name="l00464"></a>00464 
<a name="l00465"></a>00465     <span class="keywordflow">do</span>
<a name="l00466"></a>00466     {
<a name="l00467"></a>00467         <span class="keywordflow">while</span> ((<a class="code" href="main_8c.html#d3f87c8a272c3442f80fe3a4af4108de" title="Wektor zredukowanych dochodowosci .">v_</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[i]] &gt; x)||((fabs(<a class="code" href="main_8c.html#d3f87c8a272c3442f80fe3a4af4108de" title="Wektor zredukowanych dochodowosci .">v_</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[i]]-x)&lt;10e-9)&amp;&amp;(<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[i]]&gt;<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[midIndex])))
<a name="l00468"></a>00468             ++i;
<a name="l00469"></a>00469         <span class="keywordflow">while</span> ((<a class="code" href="main_8c.html#d3f87c8a272c3442f80fe3a4af4108de" title="Wektor zredukowanych dochodowosci .">v_</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[j]] &lt; x)||((fabs(<a class="code" href="main_8c.html#d3f87c8a272c3442f80fe3a4af4108de" title="Wektor zredukowanych dochodowosci .">v_</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[j]]-x)&lt;10e-9)&amp;&amp;(<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[j]]&lt;<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[midIndex])))
<a name="l00470"></a>00470             --j;
<a name="l00471"></a>00471         <span class="keywordflow">if</span> (i&lt;=j)
<a name="l00472"></a>00472         {
<a name="l00473"></a>00473             <span class="keywordtype">int</span> intTmp = <a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[i];
<a name="l00474"></a>00474             <a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[i] = <a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[j];
<a name="l00475"></a>00475             <a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[j] = intTmp;
<a name="l00476"></a>00476 
<a name="l00477"></a>00477             ++i;
<a name="l00478"></a>00478             --j;
<a name="l00479"></a>00479         }
<a name="l00480"></a>00480     }
<a name="l00481"></a>00481     <span class="keywordflow">while</span> (i &lt; j);
<a name="l00482"></a>00482 
<a name="l00483"></a>00483     <span class="keywordflow">if</span> (Lo &lt; j)
<a name="l00484"></a>00484         <a class="code" href="main_8c.html#316b792d3515c55086527d4a6aa7a386">qSort</a>(Lo, j);
<a name="l00485"></a>00485     <span class="keywordflow">if</span> (Hi &gt; i)
<a name="l00486"></a>00486         <a class="code" href="main_8c.html#316b792d3515c55086527d4a6aa7a386">qSort</a>(i, Hi);
<a name="l00487"></a>00487 }
<a name="l00488"></a>00488 <span class="comment">/* ======================================================================</span>
<a name="l00489"></a>00489 <span class="comment"> *  sortV</span>
<a name="l00490"></a>00490 <span class="comment"> * ====================================================================== */</span>
<a name="l00497"></a><a class="code" href="main_8h.html#6e789198fc2fe0924eda2fd9034f520e">00497</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#6e789198fc2fe0924eda2fd9034f520e">Sortuj</a>()
<a name="l00498"></a>00498 {
<a name="l00499"></a>00499     <a class="code" href="main_8c.html#316b792d3515c55086527d4a6aa7a386">qSort</a>(1,<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>);
<a name="l00500"></a>00500 
<a name="l00501"></a>00501 
<a name="l00502"></a>00502     <span class="keywordtype">int</span> k;
<a name="l00503"></a>00503     <span class="keywordflow">for</span> (k=1; k&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; k++)
<a name="l00504"></a>00504         <a class="code" href="main_8c.html#4cba98c6387bd12a0acde1fe002efd63" title="Wektor okresla, ktory w kolejnosci malejacej dochodowosci jest i-ty podmiot. .">ki</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[k]] = k; <span class="comment">// zapewnienie poprawnego ulozenia wektora ki</span>
<a name="l00505"></a>00505 }
<a name="l00506"></a>00506 
<a name="l00507"></a>00507 
<a name="l00508"></a>00508 
<a name="l00509"></a>00509 <span class="comment">/* ======================================================================</span>
<a name="l00510"></a>00510 <span class="comment"> *  WypiszWektory</span>
<a name="l00511"></a>00511 <span class="comment"> * ====================================================================== */</span>
<a name="l00517"></a><a class="code" href="main_8c.html#644a6088014dbafc3c8055c4801a9a7b">00517</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#644a6088014dbafc3c8055c4801a9a7b">WypiszWektory</a>(<span class="keywordtype">int</span> vector_mask, <span class="keywordtype">int</span> sort_option)
<a name="l00518"></a>00518 {
<a name="l00519"></a>00519     <span class="keywordtype">int</span> i,k;
<a name="l00520"></a>00520     <span class="keywordflow">if</span> ((sort_option == <a class="code" href="main_8h.html#6c2e0ef3768d7df3cd7565c3d4d5a944">SORT_I</a>) &amp;&amp; (vector_mask &amp;&amp; <a class="code" href="main_8h.html#58961bee5268baf32d9ca9ac51bcf126">MSK_INDEX</a>))
<a name="l00521"></a>00521     {
<a name="l00522"></a>00522         <span class="keywordflow">if</span> (vector_mask &amp; <a class="code" href="main_8h.html#7f0b6817300121163223ef6a0a6303f5">MSK_TYTUL</a>)
<a name="l00523"></a>00523         {
<a name="l00524"></a>00524             printf(<span class="stringliteral">"\n\nPosortowane wg. poczatkowych indeksow :\n"</span>);
<a name="l00525"></a>00525         }
<a name="l00526"></a>00526         printf(<span class="stringliteral">" i = ["</span>);
<a name="l00527"></a>00527         <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l00528"></a>00528             printf(<span class="stringliteral">" %8d"</span>,i);
<a name="l00529"></a>00529         printf(<span class="stringliteral">"   ]\n"</span>);
<a name="l00530"></a>00530 
<a name="l00531"></a>00531         printf(<span class="stringliteral">" k = ["</span>);
<a name="l00532"></a>00532         <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l00533"></a>00533             printf(<span class="stringliteral">" %8d"</span>,<a class="code" href="main_8c.html#4cba98c6387bd12a0acde1fe002efd63" title="Wektor okresla, ktory w kolejnosci malejacej dochodowosci jest i-ty podmiot. .">ki</a>[i]);
<a name="l00534"></a>00534         printf(<span class="stringliteral">"   ]\n"</span>);
<a name="l00535"></a>00535     }
<a name="l00536"></a>00536     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (vector_mask &amp;&amp; <a class="code" href="main_8h.html#58961bee5268baf32d9ca9ac51bcf126">MSK_INDEX</a>)
<a name="l00537"></a>00537     {
<a name="l00538"></a>00538         <span class="keywordflow">if</span> (vector_mask &amp; <a class="code" href="main_8h.html#7f0b6817300121163223ef6a0a6303f5">MSK_TYTUL</a>)
<a name="l00539"></a>00539         {
<a name="l00540"></a>00540             printf(<span class="stringliteral">"\n\nPosortowane wg. malejacych wskaznikow dochodowosci :\n"</span>);
<a name="l00541"></a>00541         }
<a name="l00542"></a>00542         printf(<span class="stringliteral">" k = ["</span>);
<a name="l00543"></a>00543         <span class="keywordflow">for</span> (k=1; k&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; k++)
<a name="l00544"></a>00544             printf(<span class="stringliteral">" %8d"</span>,k);
<a name="l00545"></a>00545         printf(<span class="stringliteral">"   ]\n"</span>);
<a name="l00546"></a>00546 
<a name="l00547"></a>00547         printf(<span class="stringliteral">" i = ["</span>);
<a name="l00548"></a>00548         <span class="keywordflow">for</span> (k=1; k&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; k++)
<a name="l00549"></a>00549             printf(<span class="stringliteral">" %8d"</span>,<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>
<a name="l00550"></a>00550 
<a name="l00551"></a>00551                    [k]);
<a name="l00552"></a>00552         printf(<span class="stringliteral">"   ]\n"</span>);
<a name="l00553"></a>00553     }
<a name="l00554"></a>00554 
<a name="l00555"></a>00555     <span class="keywordflow">if</span> (vector_mask &amp; <a class="code" href="main_8h.html#e00a20f61164fb74cb09105d2f4348c8">MSK_P</a>)
<a name="l00556"></a>00556     {
<a name="l00557"></a>00557         printf(<span class="stringliteral">" p = ["</span>);
<a name="l00558"></a>00558         <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l00559"></a>00559         {
<a name="l00560"></a>00560             <span class="keywordflow">if</span> (sort_option == <a class="code" href="main_8h.html#6c2e0ef3768d7df3cd7565c3d4d5a944">SORT_I</a>)
<a name="l00561"></a>00561                 printf(<span class="stringliteral">" %8d"</span>,<a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[i]);
<a name="l00562"></a>00562             <span class="keywordflow">if</span> (sort_option == <a class="code" href="main_8h.html#f2c5fd4a2157bbaddee5c93c0cbebb2f">SORT_K</a>)
<a name="l00563"></a>00563                 printf(<span class="stringliteral">" %8d"</span>,<a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[i]]);
<a name="l00564"></a>00564         }
<a name="l00565"></a>00565         printf(<span class="stringliteral">"   ]\n"</span>);
<a name="l00566"></a>00566     }
<a name="l00567"></a>00567 
<a name="l00568"></a>00568     <span class="keywordflow">if</span>  (vector_mask &amp; <a class="code" href="main_8h.html#c4c455795b32257010c9be2b845bddce">MSK_P_</a>)
<a name="l00569"></a>00569     {
<a name="l00570"></a>00570         printf(<span class="stringliteral">" p_= [ "</span>);
<a name="l00571"></a>00571         <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l00572"></a>00572         {
<a name="l00573"></a>00573             <span class="keywordflow">if</span> (sort_option == <a class="code" href="main_8h.html#6c2e0ef3768d7df3cd7565c3d4d5a944">SORT_I</a>)
<a name="l00574"></a>00574                 printf(<span class="stringliteral">" %7.4f "</span>,<a class="code" href="main_8c.html#eb52211fe1c73eb9c9d5568074d3013c" title="Wektor profitow zredukowanych, tj. .">p_</a>[i]);
<a name="l00575"></a>00575             <span class="keywordflow">if</span> (sort_option == <a class="code" href="main_8h.html#f2c5fd4a2157bbaddee5c93c0cbebb2f">SORT_K</a>)
<a name="l00576"></a>00576                 printf(<span class="stringliteral">" %7.4f "</span>,<a class="code" href="main_8c.html#eb52211fe1c73eb9c9d5568074d3013c" title="Wektor profitow zredukowanych, tj. .">p_</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[i]]);
<a name="l00577"></a>00577         }
<a name="l00578"></a>00578         printf(<span class="stringliteral">"  ]\n"</span>);
<a name="l00579"></a>00579     }
<a name="l00580"></a>00580     <span class="keywordflow">if</span> (vector_mask &amp; <a class="code" href="main_8h.html#4c4b917a9256232b587e9af27900045e">MSK_W</a>)
<a name="l00581"></a>00581     {
<a name="l00582"></a>00582         printf(<span class="stringliteral">" w = ["</span>);
<a name="l00583"></a>00583         <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l00584"></a>00584         {
<a name="l00585"></a>00585             <span class="keywordflow">if</span> (sort_option == <a class="code" href="main_8h.html#6c2e0ef3768d7df3cd7565c3d4d5a944">SORT_I</a>)
<a name="l00586"></a>00586                 printf(<span class="stringliteral">" %8d"</span>,<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[i]);
<a name="l00587"></a>00587             <span class="keywordflow">if</span> (sort_option == <a class="code" href="main_8h.html#f2c5fd4a2157bbaddee5c93c0cbebb2f">SORT_K</a>)
<a name="l00588"></a>00588                 printf(<span class="stringliteral">" %8d"</span>,<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[i]]);
<a name="l00589"></a>00589         }
<a name="l00590"></a>00590         printf(<span class="stringliteral">"   ]\n"</span>);
<a name="l00591"></a>00591     }
<a name="l00592"></a>00592 
<a name="l00593"></a>00593     <span class="keywordflow">if</span> (vector_mask &amp; <a class="code" href="main_8h.html#fe6b2fe5bc7084afbe5f76d0e4be4d0f">MSK_V</a>)
<a name="l00594"></a>00594     {
<a name="l00595"></a>00595         printf(<span class="stringliteral">" v = [ "</span>);
<a name="l00596"></a>00596         <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l00597"></a>00597         {
<a name="l00598"></a>00598             <span class="keywordflow">if</span> (sort_option == <a class="code" href="main_8h.html#6c2e0ef3768d7df3cd7565c3d4d5a944">SORT_I</a>)
<a name="l00599"></a>00599                 printf(<span class="stringliteral">" %7.4f "</span>,<a class="code" href="main_8c.html#18edff6f6f8cc7071adfd9bc826378ef" title="Wektor bazowych dochodowosci .">v</a>[i]);
<a name="l00600"></a>00600             <span class="keywordflow">if</span> (sort_option == <a class="code" href="main_8h.html#f2c5fd4a2157bbaddee5c93c0cbebb2f">SORT_K</a>)
<a name="l00601"></a>00601                 printf(<span class="stringliteral">" %7.4f "</span>,<a class="code" href="main_8c.html#18edff6f6f8cc7071adfd9bc826378ef" title="Wektor bazowych dochodowosci .">v</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[i]]);
<a name="l00602"></a>00602         }
<a name="l00603"></a>00603         printf(<span class="stringliteral">"  ]\n"</span>);
<a name="l00604"></a>00604     }
<a name="l00605"></a>00605 
<a name="l00606"></a>00606     <span class="keywordflow">if</span> (vector_mask &amp; <a class="code" href="main_8h.html#b46c763f901435183a60a90c8065135f">MSK_V_</a>)
<a name="l00607"></a>00607     {
<a name="l00608"></a>00608         printf(<span class="stringliteral">" v_= [ "</span>);
<a name="l00609"></a>00609         <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l00610"></a>00610         {
<a name="l00611"></a>00611             <span class="keywordflow">if</span> (sort_option == <a class="code" href="main_8h.html#6c2e0ef3768d7df3cd7565c3d4d5a944">SORT_I</a>)
<a name="l00612"></a>00612                 printf(<span class="stringliteral">" %7.4f "</span>,<a class="code" href="main_8c.html#d3f87c8a272c3442f80fe3a4af4108de" title="Wektor zredukowanych dochodowosci .">v_</a>[i]);
<a name="l00613"></a>00613             <span class="keywordflow">if</span> (sort_option == <a class="code" href="main_8h.html#f2c5fd4a2157bbaddee5c93c0cbebb2f">SORT_K</a>)
<a name="l00614"></a>00614                 printf(<span class="stringliteral">" %7.4f "</span>,<a class="code" href="main_8c.html#d3f87c8a272c3442f80fe3a4af4108de" title="Wektor zredukowanych dochodowosci .">v_</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[i]]);
<a name="l00615"></a>00615         }
<a name="l00616"></a>00616         printf(<span class="stringliteral">"  ]\n"</span>);
<a name="l00617"></a>00617     }
<a name="l00618"></a>00618 
<a name="l00619"></a>00619     <span class="keywordflow">if</span> (vector_mask &amp; <a class="code" href="main_8h.html#072e387394eca86e5be43efef72251cf">MSK_XR</a>)
<a name="l00620"></a>00620     {
<a name="l00621"></a>00621         printf(<span class="stringliteral">" xr= [ "</span>);
<a name="l00622"></a>00622         <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l00623"></a>00623         {
<a name="l00624"></a>00624             <span class="keywordflow">if</span> (sort_option == <a class="code" href="main_8h.html#6c2e0ef3768d7df3cd7565c3d4d5a944">SORT_I</a>)
<a name="l00625"></a>00625                 printf(<span class="stringliteral">" %7.4f "</span>,<a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[i]);
<a name="l00626"></a>00626             <span class="keywordflow">if</span> (sort_option == <a class="code" href="main_8h.html#f2c5fd4a2157bbaddee5c93c0cbebb2f">SORT_K</a>)
<a name="l00627"></a>00627                 printf(<span class="stringliteral">" %7.4f "</span>,<a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[i]]);
<a name="l00628"></a>00628         }
<a name="l00629"></a>00629         printf(<span class="stringliteral">"  ]\n"</span>);
<a name="l00630"></a>00630     }
<a name="l00631"></a>00631 }
<a name="l00632"></a>00632 
<a name="l00633"></a>00633 
<a name="l00634"></a>00634 <span class="comment">/* ======================================================================</span>
<a name="l00635"></a>00635 <span class="comment"> *  SecureFree</span>
<a name="l00636"></a>00636 <span class="comment"> * ====================================================================== */</span>
<a name="l00641"></a><a class="code" href="main_8c.html#587d85ea68f70d86793ef2e32f75d445">00641</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#587d85ea68f70d86793ef2e32f75d445">SecureFree</a>(<span class="keywordtype">void</span> *pointer)
<a name="l00642"></a>00642 {
<a name="l00643"></a>00643     <span class="keywordflow">if</span> (pointer != NULL)
<a name="l00644"></a>00644         free(pointer);
<a name="l00645"></a>00645 }
<a name="l00646"></a>00646 
<a name="l00647"></a>00647 
<a name="l00648"></a>00648 <span class="comment">/* ======================================================================</span>
<a name="l00649"></a>00649 <span class="comment"> *  ZwolnijPamiec</span>
<a name="l00650"></a>00650 <span class="comment"> * ====================================================================== */</span>
<a name="l00655"></a><a class="code" href="main_8h.html#01f7419ee78625ea24a0522dbd13917c">00655</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#01f7419ee78625ea24a0522dbd13917c">ZwolnijPamiec</a>()
<a name="l00656"></a>00656 {
<a name="l00657"></a>00657     <a class="code" href="main_8c.html#587d85ea68f70d86793ef2e32f75d445">SecureFree</a>(<a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>);
<a name="l00658"></a>00658     <a class="code" href="main_8c.html#587d85ea68f70d86793ef2e32f75d445">SecureFree</a>(<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>);
<a name="l00659"></a>00659     <a class="code" href="main_8c.html#587d85ea68f70d86793ef2e32f75d445">SecureFree</a>(<a class="code" href="main_8c.html#18edff6f6f8cc7071adfd9bc826378ef" title="Wektor bazowych dochodowosci .">v</a>);
<a name="l00660"></a>00660     <a class="code" href="main_8c.html#587d85ea68f70d86793ef2e32f75d445">SecureFree</a>(<a class="code" href="main_8c.html#eb52211fe1c73eb9c9d5568074d3013c" title="Wektor profitow zredukowanych, tj. .">p_</a>);
<a name="l00661"></a>00661     <a class="code" href="main_8c.html#587d85ea68f70d86793ef2e32f75d445">SecureFree</a>(<a class="code" href="main_8c.html#d3f87c8a272c3442f80fe3a4af4108de" title="Wektor zredukowanych dochodowosci .">v_</a>);
<a name="l00662"></a>00662     <a class="code" href="main_8c.html#587d85ea68f70d86793ef2e32f75d445">SecureFree</a>(<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>);
<a name="l00663"></a>00663     <a class="code" href="main_8c.html#587d85ea68f70d86793ef2e32f75d445">SecureFree</a>(<a class="code" href="main_8c.html#4cba98c6387bd12a0acde1fe002efd63" title="Wektor okresla, ktory w kolejnosci malejacej dochodowosci jest i-ty podmiot. .">ki</a>);
<a name="l00664"></a>00664     <a class="code" href="main_8c.html#587d85ea68f70d86793ef2e32f75d445">SecureFree</a>(<a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>);
<a name="l00665"></a>00665 }
<a name="l00666"></a>00666 
<a name="l00667"></a>00667 <span class="comment">/* ======================================================================</span>
<a name="l00668"></a>00668 <span class="comment"> *  ZnajdzPoczatkowaLambda2</span>
<a name="l00669"></a>00669 <span class="comment"> * ====================================================================== */</span>
<a name="l00675"></a><a class="code" href="main_8c.html#bb8f4b70c506d3745ffd24352bb42aca">00675</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#bb8f4b70c506d3745ffd24352bb42aca">ZnajdzPoczatkowaLambda2</a>()
<a name="l00676"></a>00676 {
<a name="l00677"></a>00677     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l00678"></a>00678     {
<a name="l00679"></a>00679         printf(<span class="stringliteral">"---- ZnajdzPoczatkowaLambda2 ---- \n"</span>);
<a name="l00680"></a>00680         printf(<span class="stringliteral">"Szukamy K-tej najwiekszej wagi p. K = %d.\n"</span>,<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>);
<a name="l00681"></a>00681     }
<a name="l00682"></a>00682     <span class="keywordtype">int</span>* p_sorted = (<span class="keywordtype">int</span> *) malloc(1+ <a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a> * <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>));
<a name="l00683"></a>00683 
<a name="l00684"></a>00684     <span class="keywordtype">int</span> i;
<a name="l00685"></a>00685     <span class="keywordflow">for</span> (i=1;i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>;i++)
<a name="l00686"></a>00686         p_sorted[i] = <a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[i];
<a name="l00687"></a>00687     i = 1;
<a name="l00688"></a>00688     <span class="keywordtype">int</span> j;
<a name="l00689"></a>00689     <span class="keywordtype">int</span> p_ind=0;
<a name="l00690"></a>00690     <span class="keywordtype">int</span> maxp,tmp;
<a name="l00691"></a>00691 
<a name="l00692"></a>00692     <span class="comment">// sortowanie babelkowe</span>
<a name="l00693"></a>00693     <span class="keywordflow">while</span> (i&lt;=<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>)
<a name="l00694"></a>00694     {
<a name="l00695"></a>00695         maxp = 0;
<a name="l00696"></a>00696         j = i;
<a name="l00697"></a>00697         <span class="comment">// znalezienie</span>
<a name="l00698"></a>00698         <span class="keywordflow">while</span> (j &lt;= <a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>)
<a name="l00699"></a>00699         {
<a name="l00700"></a>00700             <span class="keywordflow">if</span> (maxp &lt; p_sorted[j])
<a name="l00701"></a>00701             {
<a name="l00702"></a>00702                 maxp = p_sorted[j];
<a name="l00703"></a>00703                 p_ind = j;
<a name="l00704"></a>00704             }
<a name="l00705"></a>00705             <span class="keywordflow">else</span>
<a name="l00706"></a>00706                 j++;
<a name="l00707"></a>00707         }
<a name="l00708"></a>00708         <span class="comment">//zamiana z</span>
<a name="l00709"></a>00709         tmp = p_sorted[i];
<a name="l00710"></a>00710         p_sorted[i] = p_sorted[p_ind];
<a name="l00711"></a>00711         p_sorted[p_ind] = tmp;
<a name="l00712"></a>00712         i++;
<a name="l00713"></a>00713     }
<a name="l00714"></a>00714     <span class="comment">// znaleziono lambda_2</span>
<a name="l00715"></a>00715     <a class="code" href="main_8c.html#d4d5373fa78e7853374abf4cd8ed277d" title="W kazdej iteracji aktualna wartosc .">lambda_2</a> = p_sorted[<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>];
<a name="l00716"></a>00716 
<a name="l00717"></a>00717     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l00718"></a>00718         printf(<span class="stringliteral">"---- ZnajdzPoczatkowaLambda2 koniec. mem:[lambda_2=%f]---- \n"</span>,<a class="code" href="main_8c.html#d4d5373fa78e7853374abf4cd8ed277d" title="W kazdej iteracji aktualna wartosc .">lambda_2</a>);
<a name="l00719"></a>00719 }
<a name="l00720"></a>00720 
<a name="l00721"></a>00721 <span class="comment">/* ======================================================================</span>
<a name="l00722"></a>00722 <span class="comment"> *  ObliczStanAlokacji</span>
<a name="l00723"></a>00723 <span class="comment"> * ====================================================================== */</span>
<a name="l00734"></a><a class="code" href="main_8c.html#a5c3bae27b8fe935fe170a47139f65c2">00734</a> <span class="keywordtype">double</span> <a class="code" href="main_8c.html#a5c3bae27b8fe935fe170a47139f65c2" title="Na podstawie wartosci wektora  oblicza wartosc alokacji oraz wolny zasob.">ObliczStanAlokacji</a>()
<a name="l00735"></a>00735 {
<a name="l00736"></a>00736     <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a> = 0;
<a name="l00737"></a>00737     <a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a> = <a class="code" href="main_8c.html#4e1e0e72dd773439e333c84dd762a9c3" title="Maksymalna wielkosc alokacji zasobow.">c</a>;
<a name="l00738"></a>00738 
<a name="l00739"></a>00739     <span class="keywordtype">int</span> i;
<a name="l00740"></a>00740 
<a name="l00741"></a>00741     <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l00742"></a>00742     {
<a name="l00743"></a>00743         <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a> += (double)<a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[i]*<a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[i];
<a name="l00744"></a>00744         <a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a> -= (double)<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[i]*<a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[i];
<a name="l00745"></a>00745     }
<a name="l00746"></a>00746     <span class="keywordflow">return</span> <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a>;
<a name="l00747"></a>00747 }
<a name="l00748"></a>00748 
<a name="l00749"></a>00749 <span class="comment">/* ======================================================================</span>
<a name="l00750"></a>00750 <span class="comment"> *  AlokujZachlannie</span>
<a name="l00751"></a>00751 <span class="comment"> * ====================================================================== */</span>
<a name="l00761"></a><a class="code" href="main_8c.html#839a6caa67dc71f4f5b8502ae6d3e3f9">00761</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#839a6caa67dc71f4f5b8502ae6d3e3f9" title="Funkcja znajduje rozwiazanie problemu tzw. metoda zachlanna.">AlokujZachlannie</a>()
<a name="l00762"></a>00762 {
<a name="l00763"></a>00763     <span class="keywordtype">int</span> j = 1;
<a name="l00764"></a>00764 
<a name="l00765"></a>00765     <span class="comment">// poczatkowe czyszczenie zawartosci plecaka</span>
<a name="l00766"></a>00766     <a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a> = <a class="code" href="main_8c.html#4e1e0e72dd773439e333c84dd762a9c3" title="Maksymalna wielkosc alokacji zasobow.">c</a>;
<a name="l00767"></a>00767     <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a> = 0;
<a name="l00768"></a>00768     <span class="keywordflow">for</span> (j=1; j&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; j++)
<a name="l00769"></a>00769         <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[j] = 0;
<a name="l00770"></a>00770 
<a name="l00771"></a>00771     j = 1;
<a name="l00772"></a>00772 
<a name="l00773"></a>00773     <span class="keywordflow">while</span> (<a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a> &gt;= <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[j]] &amp;&amp; j &lt;= <a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>)
<a name="l00774"></a>00774     {
<a name="l00775"></a>00775         <a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a> -= <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[j]];
<a name="l00776"></a>00776         <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a> += (double) <a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[ik[j]];
<a name="l00777"></a>00777         <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[ik[j]] = 1;
<a name="l00778"></a>00778         j++;
<a name="l00779"></a>00779     }
<a name="l00780"></a>00780 
<a name="l00781"></a>00781     <span class="keywordflow">if</span> (j != <a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>+1)
<a name="l00782"></a>00782     {
<a name="l00783"></a>00783         <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[j]] = (double) <a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a>/<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[ik[j]];
<a name="l00784"></a>00784         <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a> += (double) <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[ik[j]]*<a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[ik[j]];
<a name="l00785"></a>00785 
<a name="l00786"></a>00786         <a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a> = j;
<a name="l00787"></a>00787         <a class="code" href="main_8c.html#ba4ddc236971684b95ae11d622e50237" title="Aktualna wartosc C(  ).">aktualneC</a> = <a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>-1 + <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[ik[<a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>]];
<a name="l00788"></a>00788         <a class="code" href="main_8c.html#262072a74026166e1c7b6bf6f135791b" title="Indeks elementu granicznego (wg nomenklatury i.">i_s</a> = ik[<a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>];
<a name="l00789"></a>00789     }
<a name="l00790"></a>00790 
<a name="l00791"></a>00791     <span class="keywordflow">else</span>
<a name="l00792"></a>00792     {
<a name="l00793"></a>00793         <span class="comment">// przydzielismy zasob WSZYSTKIM elementom</span>
<a name="l00794"></a>00794         <a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a> = <a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>+1;
<a name="l00795"></a>00795         <a class="code" href="main_8c.html#262072a74026166e1c7b6bf6f135791b" title="Indeks elementu granicznego (wg nomenklatury i.">i_s</a> = <a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>+1;
<a name="l00796"></a>00796         <a class="code" href="main_8c.html#ba4ddc236971684b95ae11d622e50237" title="Aktualna wartosc C(  ).">aktualneC</a> = <a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>;
<a name="l00797"></a>00797     }
<a name="l00798"></a>00798 }
<a name="l00799"></a>00799 
<a name="l00800"></a>00800 <span class="comment">/* ======================================================================</span>
<a name="l00801"></a>00801 <span class="comment"> *  AktualizujZredukowaneWagi</span>
<a name="l00802"></a>00802 <span class="comment"> * ====================================================================== */</span>
<a name="l00807"></a><a class="code" href="main_8c.html#e0efa66f476cffdfc64cb39068721c92">00807</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#e0efa66f476cffdfc64cb39068721c92" title="Funkcja aktualizuje wartosci  oraz  w wektorach na podstawie aktualnej wartosci ...">AktualizujZredukowaneWagi</a>()
<a name="l00808"></a>00808 {
<a name="l00809"></a>00809     <span class="keywordtype">int</span> i;
<a name="l00810"></a>00810     <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l00811"></a>00811     {
<a name="l00812"></a>00812         <a class="code" href="main_8c.html#eb52211fe1c73eb9c9d5568074d3013c" title="Wektor profitow zredukowanych, tj. .">p_</a>[i] = (double) <a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[i] - <a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a>;
<a name="l00813"></a>00813         <a class="code" href="main_8c.html#d3f87c8a272c3442f80fe3a4af4108de" title="Wektor zredukowanych dochodowosci .">v_</a>[i] = (double) <a class="code" href="main_8c.html#eb52211fe1c73eb9c9d5568074d3013c" title="Wektor profitow zredukowanych, tj. .">p_</a>[i]/ (<span class="keywordtype">double</span>) <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[i];
<a name="l00814"></a>00814     }
<a name="l00815"></a>00815 }
<a name="l00816"></a>00816 
<a name="l00817"></a>00817 <span class="comment">/* ======================================================================</span>
<a name="l00818"></a>00818 <span class="comment"> *  C</span>
<a name="l00819"></a>00819 <span class="comment"> * ====================================================================== */</span>
<a name="l00831"></a><a class="code" href="main_8c.html#3d9a7e827f0aea2b3b298ede3ec7427c">00831</a> <span class="keywordtype">double</span> <a class="code" href="main_8c.html#3d9a7e827f0aea2b3b298ede3ec7427c" title="Funkcja obliczajaca C wyznacza sume x-ow (elementow, ktorym przydzielono zasob).">C</a>(<span class="keywordtype">double</span> argLambda)
<a name="l00832"></a>00832 {
<a name="l00833"></a>00833     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l00834"></a>00834         printf(<span class="stringliteral">"\nZnajdowanie C(%f)...\n"</span>,argLambda);
<a name="l00835"></a>00835     <a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a> = argLambda;
<a name="l00836"></a>00836 
<a name="l00837"></a>00837     <span class="comment">/* aktualizacje wartosci p_ (zredukowanych) i wspolczynnikow dochodowosci v_</span>
<a name="l00838"></a>00838 <span class="comment">     */</span>
<a name="l00839"></a>00839     <a class="code" href="main_8c.html#e0efa66f476cffdfc64cb39068721c92" title="Funkcja aktualizuje wartosci  oraz  w wektorach na podstawie aktualnej wartosci ...">AktualizujZredukowaneWagi</a>();
<a name="l00840"></a>00840     <a class="code" href="main_8c.html#6e789198fc2fe0924eda2fd9034f520e">Sortuj</a>();
<a name="l00841"></a>00841     <a class="code" href="main_8c.html#839a6caa67dc71f4f5b8502ae6d3e3f9" title="Funkcja znajduje rozwiazanie problemu tzw. metoda zachlanna.">AlokujZachlannie</a>();
<a name="l00842"></a>00842 
<a name="l00843"></a>00843     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l00844"></a>00844     {
<a name="l00845"></a>00845         printf(<span class="stringliteral">"C(%.2f) = %f,\t"</span>,<a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a>,<a class="code" href="main_8c.html#ba4ddc236971684b95ae11d622e50237" title="Aktualna wartosc C(  ).">aktualneC</a>);
<a name="l00846"></a>00846         printf(<span class="stringliteral">"s(%.2f) = %d\n\n"</span>,<a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a>,<a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>);
<a name="l00847"></a>00847     }
<a name="l00848"></a>00848     <span class="keywordflow">return</span> <a class="code" href="main_8c.html#ba4ddc236971684b95ae11d622e50237" title="Aktualna wartosc C(  ).">aktualneC</a>;
<a name="l00849"></a>00849 }
<a name="l00850"></a>00850 
<a name="l00851"></a>00851 <span class="comment">/* ======================================================================</span>
<a name="l00852"></a>00852 <span class="comment"> *  Poprawianie lambda</span>
<a name="l00853"></a>00853 <span class="comment"> * ====================================================================== */</span>
<a name="l00863"></a><a class="code" href="main_8c.html#a8e5877834c7bb319ebb1a912bcc9399">00863</a> <span class="keywordtype">int</span> <a class="code" href="main_8c.html#a8e5877834c7bb319ebb1a912bcc9399" title="Poprawianie lambda w trakcie rozwiazywania relaksacji.">PoprawLambda</a>(<span class="keywordtype">int</span> typPoprawy)
<a name="l00864"></a>00864 {
<a name="l00865"></a>00865 
<a name="l00866"></a>00866     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l00867"></a>00867         printf(<span class="stringliteral">"\nFUNKCJA FINDBETTERLAMBDA.------------------------------------\n"</span>);
<a name="l00868"></a>00868     <span class="keywordtype">int</span> k = 1;
<a name="l00869"></a>00869     <span class="keywordtype">int</span>* i_itemsToCheck = ( <span class="keywordtype">int</span> * ) malloc( 1+<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a> * <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>) ); <span class="comment">//indeksy (pierwotne) elementow do znalezienia min</span>
<a name="l00870"></a>00870 
<a name="l00871"></a>00871     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l00872"></a>00872         printf(<span class="stringliteral">"Szukamy "</span>);
<a name="l00873"></a>00873 
<a name="l00874"></a>00874     <span class="keywordflow">if</span> (typPoprawy == <a class="code" href="main_8c.html#090b5d90b0350e728a076aeef5b1184b">ZNAJDZ_MIN_WIEKSZA</a>)
<a name="l00875"></a>00875     { <span class="comment">//min</span>
<a name="l00876"></a>00876         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l00877"></a>00877         {
<a name="l00878"></a>00878             printf(<span class="stringliteral">"najmniejszej lambda WIEKSZEJ OD %f\n"</span>,<a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a>);
<a name="l00879"></a>00879             <a class="code" href="main_8c.html#644a6088014dbafc3c8055c4801a9a7b">WypiszWektory</a>(<a class="code" href="main_8h.html#58961bee5268baf32d9ca9ac51bcf126">MSK_INDEX</a>|<a class="code" href="main_8h.html#c4c455795b32257010c9be2b845bddce">MSK_P_</a>|<a class="code" href="main_8h.html#4c4b917a9256232b587e9af27900045e">MSK_W</a>|<a class="code" href="main_8h.html#b46c763f901435183a60a90c8065135f">MSK_V_</a>,<a class="code" href="main_8h.html#f2c5fd4a2157bbaddee5c93c0cbebb2f">SORT_K</a>);
<a name="l00880"></a>00880             printf(<span class="stringliteral">"s = %d\n"</span>,<a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>);
<a name="l00881"></a>00881             printf(<span class="stringliteral">"Kandydaci do utraty zasobu: { "</span>);
<a name="l00882"></a>00882         }
<a name="l00883"></a>00883         <span class="keywordtype">int</span> jest_kandydat_do_utraty = 0;
<a name="l00884"></a>00884         <span class="keywordflow">while</span> (k&lt;<a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>)
<a name="l00885"></a>00885         {
<a name="l00886"></a>00886             <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[k]] &lt; <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[<a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>]])
<a name="l00887"></a>00887             {
<a name="l00888"></a>00888                 jest_kandydat_do_utraty = 1;
<a name="l00889"></a>00889                 i_itemsToCheck[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[k]] = 1;
<a name="l00890"></a>00890                 <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l00891"></a>00891                     printf(<span class="stringliteral">"%d "</span>,ik[k]);
<a name="l00892"></a>00892             }
<a name="l00893"></a>00893             k++;
<a name="l00894"></a>00894         }
<a name="l00895"></a>00895 
<a name="l00896"></a>00896         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l00897"></a>00897         {
<a name="l00898"></a>00898             <span class="keywordflow">if</span> (!jest_kandydat_do_utraty)
<a name="l00899"></a>00899                 printf(<span class="stringliteral">"BRAK "</span>);
<a name="l00900"></a>00900             printf(<span class="stringliteral">"}.\n"</span>);
<a name="l00901"></a>00901         }
<a name="l00902"></a>00902 
<a name="l00903"></a>00903         <span class="keywordtype">int</span> jest_kandydat_do_alokacji = 0;
<a name="l00904"></a>00904         k = <a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>+1;
<a name="l00905"></a>00905         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l00906"></a>00906             printf(<span class="stringliteral">"Kandydaci do alokacji: { "</span>);
<a name="l00907"></a>00907         <span class="keywordflow">while</span> (k&gt;<a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a> &amp;&amp; k &lt;= <a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>)
<a name="l00908"></a>00908         {
<a name="l00909"></a>00909             <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[k]] &gt; <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[<a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>]])
<a name="l00910"></a>00910             {
<a name="l00911"></a>00911                 jest_kandydat_do_alokacji = 1;
<a name="l00912"></a>00912                 i_itemsToCheck[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[k]] = 1;
<a name="l00913"></a>00913                 <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l00914"></a>00914                     printf(<span class="stringliteral">"%d "</span>,ik[k]);
<a name="l00915"></a>00915             }
<a name="l00916"></a>00916             k++;
<a name="l00917"></a>00917         }
<a name="l00918"></a>00918         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l00919"></a>00919         {
<a name="l00920"></a>00920             <span class="keywordflow">if</span> (!jest_kandydat_do_alokacji)
<a name="l00921"></a>00921                 printf(<span class="stringliteral">"BRAK "</span>);
<a name="l00922"></a>00922             printf(<span class="stringliteral">"}.\n"</span>);
<a name="l00923"></a>00923             printf(<span class="stringliteral">"Miejsce zerowe elementu s-tego = %d.\n"</span>,<a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[<a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>]]);
<a name="l00924"></a>00924         }
<a name="l00925"></a>00925         i_itemsToCheck[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[<a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>]] = 1;
<a name="l00926"></a>00926 
<a name="l00927"></a>00927         <span class="comment">// zanalizowac kiedy taka sytuacja moze miec miejsce</span>
<a name="l00928"></a>00928         <span class="keywordflow">if</span> (!jest_kandydat_do_alokacji &amp;&amp; !jest_kandydat_do_utraty)
<a name="l00929"></a>00929         {
<a name="l00930"></a>00930             <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l00931"></a>00931             {
<a name="l00932"></a>00932                 printf(<span class="stringliteral">"Nie mozna poprawic wg algorytmu, wiec pozostaje %f.\n"</span>,<a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a>);
<a name="l00933"></a>00933                 printf(<span class="stringliteral">"Przesuwamy lambde w prawo tak aby pozostawic k najbardziej dochodowych elementow.\n"</span>);
<a name="l00934"></a>00934             }
<a name="l00935"></a>00935             <a class="code" href="main_8c.html#58222620d44f880a6aec9b6a7309f4d3" title="W kazdej iteracji aktualna wartosc .">lambda_1</a> = <a class="code" href="main_8c.html#d4d5373fa78e7853374abf4cd8ed277d" title="W kazdej iteracji aktualna wartosc .">lambda_2</a>;
<a name="l00936"></a>00936             <a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a> = <a class="code" href="main_8c.html#d4d5373fa78e7853374abf4cd8ed277d" title="W kazdej iteracji aktualna wartosc .">lambda_2</a>;
<a name="l00937"></a>00937             <span class="keywordflow">return</span> 0;
<a name="l00938"></a>00938         }
<a name="l00939"></a>00939 
<a name="l00940"></a>00940         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l00941"></a>00941             printf(<span class="stringliteral">"Wybieramy minimum z : {"</span>);
<a name="l00942"></a>00942 
<a name="l00943"></a>00943         <span class="keywordtype">double</span> minLambda = 9999;
<a name="l00944"></a>00944         <span class="keywordtype">int</span> minLambdaIndex = 1;
<a name="l00945"></a>00945         <span class="keywordtype">double</span> potencjalnieMinLambda;
<a name="l00946"></a>00946 
<a name="l00947"></a>00947         <span class="keywordtype">int</span> iterator;
<a name="l00948"></a>00948         <span class="keywordflow">for</span> (iterator=1; iterator&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; iterator++)
<a name="l00949"></a>00949         {
<a name="l00950"></a>00950 
<a name="l00951"></a>00951             <span class="keywordflow">if</span> (i_itemsToCheck[iterator] == 1)
<a name="l00952"></a>00952             {
<a name="l00953"></a>00953                 <span class="keywordflow">if</span> (iterator!=ik[<a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>])
<a name="l00954"></a>00954                     potencjalnieMinLambda = (double)(<a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[iterator]*<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[ik[s]]-<a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[ik[s]]*<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[iterator])/(double)(<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[ik[s]]-<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[iterator]);
<a name="l00955"></a>00955                 <span class="keywordflow">else</span>
<a name="l00956"></a>00956                     potencjalnieMinLambda = <a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[ik[s]];
<a name="l00957"></a>00957 
<a name="l00958"></a>00958                 <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l00959"></a>00959                     printf(<span class="stringliteral">" %f "</span>,potencjalnieMinLambda);
<a name="l00960"></a>00960 
<a name="l00961"></a>00961                 <span class="keywordflow">if</span> (minLambda &gt; potencjalnieMinLambda)
<a name="l00962"></a>00962                 {
<a name="l00963"></a>00963                     minLambda = potencjalnieMinLambda;
<a name="l00964"></a>00964                     minLambdaIndex = iterator;
<a name="l00965"></a>00965                 }
<a name="l00966"></a>00966             }
<a name="l00967"></a>00967         }
<a name="l00968"></a>00968 
<a name="l00969"></a>00969         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l00970"></a>00970         {
<a name="l00971"></a>00971             printf(<span class="stringliteral">" }, czyli min = %f (x%d "</span>,minLambda,minLambdaIndex);
<a name="l00972"></a>00972             <a class="code" href="main_8c.html#4cba98c6387bd12a0acde1fe002efd63" title="Wektor okresla, ktory w kolejnosci malejacej dochodowosci jest i-ty podmiot. .">ki</a>[minLambdaIndex] &lt;= <a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a> ? printf(<span class="stringliteral">" traci zasob)\n"</span>) : printf(<span class="stringliteral">" otrzymuje zasob)\n"</span>);
<a name="l00973"></a>00973             printf(<span class="stringliteral">"\n"</span>);
<a name="l00974"></a>00974         }
<a name="l00975"></a>00975         <a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a> = minLambda;
<a name="l00976"></a>00976         <span class="keywordflow">return</span> 0;
<a name="l00977"></a>00977 
<a name="l00978"></a>00978     }
<a name="l00979"></a>00979     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (typPoprawy == <a class="code" href="main_8c.html#edc0d239bfc447fb9dc15e7a96c0a19d">ZNAJDZ_MAX_MNIEJSZA</a>)
<a name="l00980"></a>00980     {
<a name="l00981"></a>00981         <span class="comment">//max</span>
<a name="l00982"></a>00982         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l00983"></a>00983         {
<a name="l00984"></a>00984             printf(<span class="stringliteral">"najwiekszej lambda' MNIEJSZEJ OD %f\n"</span>,<a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a>);
<a name="l00985"></a>00985             <a class="code" href="main_8c.html#644a6088014dbafc3c8055c4801a9a7b">WypiszWektory</a>(<a class="code" href="main_8h.html#58961bee5268baf32d9ca9ac51bcf126">MSK_INDEX</a>|<a class="code" href="main_8h.html#c4c455795b32257010c9be2b845bddce">MSK_P_</a>|<a class="code" href="main_8h.html#4c4b917a9256232b587e9af27900045e">MSK_W</a>|<a class="code" href="main_8h.html#b46c763f901435183a60a90c8065135f">MSK_V_</a>,<a class="code" href="main_8h.html#f2c5fd4a2157bbaddee5c93c0cbebb2f">SORT_K</a>);
<a name="l00986"></a>00986 
<a name="l00987"></a>00987             printf(<span class="stringliteral">"Kandydaci do utraty zasobu: { "</span>);
<a name="l00988"></a>00988         }
<a name="l00989"></a>00989         <span class="keywordflow">while</span> (k&lt;<a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>)
<a name="l00990"></a>00990         {
<a name="l00991"></a>00991             <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[k]] &gt; <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[<a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>]])
<a name="l00992"></a>00992             {
<a name="l00993"></a>00993                 i_itemsToCheck[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[k]] = 1;
<a name="l00994"></a>00994                 <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l00995"></a>00995                     printf(<span class="stringliteral">"%d "</span>,ik[k]);
<a name="l00996"></a>00996             }
<a name="l00997"></a>00997             k++;
<a name="l00998"></a>00998         }
<a name="l00999"></a>00999         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01000"></a>01000             printf(<span class="stringliteral">"}.\n"</span>);
<a name="l01001"></a>01001 
<a name="l01002"></a>01002         k = <a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>+1;
<a name="l01003"></a>01003         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01004"></a>01004             printf(<span class="stringliteral">"Kandydaci do alokacji: { "</span>);
<a name="l01005"></a>01005         <span class="keywordflow">while</span> (k&gt;<a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a> &amp;&amp; k &lt;= <a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>)
<a name="l01006"></a>01006         {
<a name="l01007"></a>01007             <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[k]] &lt; <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[<a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>]])
<a name="l01008"></a>01008             {
<a name="l01009"></a>01009                 i_itemsToCheck[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[k]] = 1;
<a name="l01010"></a>01010                 <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01011"></a>01011                     printf(<span class="stringliteral">"%d "</span>,ik[k]);
<a name="l01012"></a>01012             }
<a name="l01013"></a>01013             k++;
<a name="l01014"></a>01014         }
<a name="l01015"></a>01015         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01016"></a>01016             printf(<span class="stringliteral">"}\n"</span>);
<a name="l01017"></a>01017 
<a name="l01018"></a>01018         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01019"></a>01019             printf(<span class="stringliteral">"Wybieramy maksimum z : {"</span>);
<a name="l01020"></a>01020 
<a name="l01021"></a>01021         <span class="keywordtype">double</span> maxLambda = -9999;
<a name="l01022"></a>01022         <span class="keywordtype">int</span> maxLambdaIndex = 1;
<a name="l01023"></a>01023         <span class="keywordtype">double</span> potencjalnieMaxLambda;
<a name="l01024"></a>01024 
<a name="l01025"></a>01025         <span class="keywordtype">int</span> iterator;
<a name="l01026"></a>01026         <span class="keywordflow">for</span> (iterator=1; iterator&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; iterator++)
<a name="l01027"></a>01027         {
<a name="l01028"></a>01028 
<a name="l01029"></a>01029             <span class="keywordflow">if</span> (i_itemsToCheck[iterator] == 1)
<a name="l01030"></a>01030             {
<a name="l01031"></a>01031                 potencjalnieMaxLambda = (double)(<a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[iterator]*<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[<a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>]]-<a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[<a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>]]*<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[iterator])/(<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[<a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>]]-<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[iterator]);
<a name="l01032"></a>01032                 <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01033"></a>01033                     printf(<span class="stringliteral">" %f "</span>,potencjalnieMaxLambda);
<a name="l01034"></a>01034                 <span class="comment">//znajdowanie maksa</span>
<a name="l01035"></a>01035                 <span class="keywordflow">if</span> (maxLambda &lt; potencjalnieMaxLambda)
<a name="l01036"></a>01036                 {
<a name="l01037"></a>01037                     maxLambda = potencjalnieMaxLambda;
<a name="l01038"></a>01038                     maxLambdaIndex = iterator;
<a name="l01039"></a>01039                 }
<a name="l01040"></a>01040             }
<a name="l01041"></a>01041         }
<a name="l01042"></a>01042         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01043"></a>01043         {
<a name="l01044"></a>01044             printf(<span class="stringliteral">" }, czyli max = %f (x%d "</span>,maxLambda,maxLambdaIndex);
<a name="l01045"></a>01045             <a class="code" href="main_8c.html#4cba98c6387bd12a0acde1fe002efd63" title="Wektor okresla, ktory w kolejnosci malejacej dochodowosci jest i-ty podmiot. .">ki</a>[maxLambdaIndex] &lt; <a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a> ? printf(<span class="stringliteral">" wypada z plecaka)\n"</span>) : printf(<span class="stringliteral">" wpada do plecaka)\n"</span>);
<a name="l01046"></a>01046         }
<a name="l01047"></a>01047         <a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a> = maxLambda;
<a name="l01048"></a>01048     }
<a name="l01049"></a>01049 
<a name="l01050"></a>01050     <span class="keywordflow">return</span> 0;
<a name="l01051"></a>01051 }
<a name="l01052"></a>01052 
<a name="l01053"></a>01053 <span class="comment">/* ======================================================================</span>
<a name="l01054"></a>01054 <span class="comment"> *  Relaksacja</span>
<a name="l01055"></a>01055 <span class="comment"> * ====================================================================== */</span>
<a name="l01060"></a><a class="code" href="main_8c.html#cdd4e11b1fc38e16d036b25d02df00f0">01060</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#cdd4e11b1fc38e16d036b25d02df00f0" title="Implementacja rozwiazania zrelaksowanego problemu KP01&amp;lt;=K.">Relaksacja</a>()
<a name="l01061"></a>01061 {
<a name="l01062"></a>01062 
<a name="l01063"></a>01063     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01064"></a>01064         printf(<span class="stringliteral">"\nFUNKCJA RELAKSACJA.------------------------------\n"</span>);
<a name="l01065"></a>01065 
<a name="l01067"></a>01067     <span class="keywordtype">int</span> i,sumaWszystkichWag = 0;
<a name="l01068"></a>01068 
<a name="l01069"></a>01069     <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l01070"></a>01070         sumaWszystkichWag += <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[i];
<a name="l01071"></a>01071     <span class="keywordflow">if</span> (sumaWszystkichWag &lt;= <a class="code" href="main_8c.html#4e1e0e72dd773439e333c84dd762a9c3" title="Maksymalna wielkosc alokacji zasobow.">c</a>)
<a name="l01072"></a>01072     {
<a name="l01073"></a>01073         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01074"></a>01074         printf(<span class="stringliteral">"Mozna przydzielic zasob wszystkim podmiotom (suma zapotrzebowan = %d, ograniczenie = %d)!\n"</span>,sumaWszystkichWag,<a class="code" href="main_8c.html#4e1e0e72dd773439e333c84dd762a9c3" title="Maksymalna wielkosc alokacji zasobow.">c</a>);
<a name="l01075"></a>01075         <span class="keywordflow">return</span>;
<a name="l01076"></a>01076     }
<a name="l01077"></a>01077     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01078"></a>01078         printf(<span class="stringliteral">"\nTest 1 (suma wag elementow &gt; c) : OK\n"</span>);
<a name="l01079"></a>01079 
<a name="l01081"></a>01081     <span class="keywordtype">int</span> minWeight = <a class="code" href="main_8c.html#4e1e0e72dd773439e333c84dd762a9c3" title="Maksymalna wielkosc alokacji zasobow.">c</a>+1;
<a name="l01082"></a>01082     <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l01083"></a>01083         minWeight = minWeight &lt; <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[i] ? minWeight : <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[i];
<a name="l01084"></a>01084     <span class="keywordflow">if</span> (minWeight &gt; <a class="code" href="main_8c.html#4e1e0e72dd773439e333c84dd762a9c3" title="Maksymalna wielkosc alokacji zasobow.">c</a>)
<a name="l01085"></a>01085     {
<a name="l01086"></a>01086         printf(<span class="stringliteral">"Najmniejsze zapotrzebowanie wieksze niz cala ilosc zasobu !\n"</span>); <span class="comment">//a co jesli K = 1?</span>
<a name="l01087"></a>01087         <span class="keywordflow">return</span>;
<a name="l01088"></a>01088     }
<a name="l01089"></a>01089     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01090"></a>01090         printf(<span class="stringliteral">"\nTest 2 (min w &lt; c) : OK\n\n"</span>);
<a name="l01091"></a>01091 
<a name="l01092"></a>01092     <a class="code" href="main_8c.html#58222620d44f880a6aec9b6a7309f4d3" title="W kazdej iteracji aktualna wartosc .">lambda_1</a> = 0;
<a name="l01093"></a>01093     <a class="code" href="main_8c.html#bb8f4b70c506d3745ffd24352bb42aca">ZnajdzPoczatkowaLambda2</a>();
<a name="l01094"></a>01094 
<a name="l01095"></a>01095     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01096"></a>01096         printf(<span class="stringliteral">"lambda_1 = %.4f\t"</span>,<a class="code" href="main_8c.html#58222620d44f880a6aec9b6a7309f4d3" title="W kazdej iteracji aktualna wartosc .">lambda_1</a>);
<a name="l01097"></a>01097     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01098"></a>01098         printf(<span class="stringliteral">"lambda_2 = %.4f\n"</span>,<a class="code" href="main_8c.html#d4d5373fa78e7853374abf4cd8ed277d" title="W kazdej iteracji aktualna wartosc .">lambda_2</a>);
<a name="l01099"></a>01099 
<a name="l01100"></a>01100     <span class="keywordtype">double</span> C_2 = <a class="code" href="main_8c.html#3d9a7e827f0aea2b3b298ede3ec7427c" title="Funkcja obliczajaca C wyznacza sume x-ow (elementow, ktorym przydzielono zasob).">C</a>(<a class="code" href="main_8c.html#d4d5373fa78e7853374abf4cd8ed277d" title="W kazdej iteracji aktualna wartosc .">lambda_2</a>);
<a name="l01101"></a>01101     <span class="keywordtype">double</span> C_1;
<a name="l01102"></a>01102     <span class="comment">//int s_1 = s;</span>
<a name="l01103"></a>01103     <span class="keywordtype">int</span> s_2 = <a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>;
<a name="l01104"></a>01104 
<a name="l01105"></a>01105     <span class="comment">// jezeli C(K-ta najwieksza p) &gt; K,</span>
<a name="l01106"></a>01106     <span class="comment">// to lambda* = lambda_2</span>
<a name="l01107"></a>01107     <span class="comment">// przydzielamy K najbardziej dochodowym podmiotom (wg wag zredukowanych)</span>
<a name="l01108"></a>01108     <span class="comment">// i koniec</span>
<a name="l01109"></a>01109     <span class="keywordflow">if</span> (C_2 &gt; <a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>)
<a name="l01110"></a>01110     {
<a name="l01111"></a>01111 
<a name="l01112"></a>01112         <a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a> = <a class="code" href="main_8c.html#d4d5373fa78e7853374abf4cd8ed277d" title="W kazdej iteracji aktualna wartosc .">lambda_2</a>;
<a name="l01113"></a>01113         <a class="code" href="main_8c.html#e0efa66f476cffdfc64cb39068721c92" title="Funkcja aktualizuje wartosci  oraz  w wektorach na podstawie aktualnej wartosci ...">AktualizujZredukowaneWagi</a>();
<a name="l01114"></a>01114         <a class="code" href="main_8c.html#6e789198fc2fe0924eda2fd9034f520e">Sortuj</a>();
<a name="l01115"></a>01115         <span class="keywordtype">int</span> k;
<a name="l01116"></a>01116         <span class="keywordflow">for</span> (k=1;k&lt;=<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>;k++)
<a name="l01117"></a>01117             <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[k]] = 1;
<a name="l01118"></a>01118         <span class="keywordflow">for</span> (k=<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>+1;k&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>;k++)
<a name="l01119"></a>01119             <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[k]] = 0;
<a name="l01120"></a>01120     }
<a name="l01121"></a>01121     <span class="keywordflow">else</span> <span class="keywordflow">if</span> ((C_1=<a class="code" href="main_8c.html#3d9a7e827f0aea2b3b298ede3ec7427c" title="Funkcja obliczajaca C wyznacza sume x-ow (elementow, ktorym przydzielono zasob).">C</a>(<a class="code" href="main_8c.html#58222620d44f880a6aec9b6a7309f4d3" title="W kazdej iteracji aktualna wartosc .">lambda_1</a>)) &lt; <a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>)
<a name="l01122"></a>01122     {
<a name="l01123"></a>01123         <a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a> = 0;
<a name="l01124"></a>01124         <a class="code" href="main_8c.html#e0efa66f476cffdfc64cb39068721c92" title="Funkcja aktualizuje wartosci  oraz  w wektorach na podstawie aktualnej wartosci ...">AktualizujZredukowaneWagi</a>();
<a name="l01125"></a>01125         <a class="code" href="main_8c.html#839a6caa67dc71f4f5b8502ae6d3e3f9" title="Funkcja znajduje rozwiazanie problemu tzw. metoda zachlanna.">AlokujZachlannie</a>();
<a name="l01126"></a>01126     }
<a name="l01127"></a>01127     <span class="keywordflow">else</span>
<a name="l01128"></a>01128     {
<a name="l01129"></a>01129 
<a name="l01130"></a>01130         <span class="keywordtype">double</span> C_1 = <a class="code" href="main_8c.html#3d9a7e827f0aea2b3b298ede3ec7427c" title="Funkcja obliczajaca C wyznacza sume x-ow (elementow, ktorym przydzielono zasob).">C</a>(<a class="code" href="main_8c.html#58222620d44f880a6aec9b6a7309f4d3" title="W kazdej iteracji aktualna wartosc .">lambda_1</a>);
<a name="l01131"></a>01131         <span class="keywordtype">int</span> s_1 = <a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>;
<a name="l01132"></a>01132 
<a name="l01133"></a>01133         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01134"></a>01134         {
<a name="l01135"></a>01135             printf(<span class="stringliteral">"C(%.2f) = %.4f\t\ts(%.2f) = %d\n"</span>,<a class="code" href="main_8c.html#58222620d44f880a6aec9b6a7309f4d3" title="W kazdej iteracji aktualna wartosc .">lambda_1</a>,C_1,<a class="code" href="main_8c.html#58222620d44f880a6aec9b6a7309f4d3" title="W kazdej iteracji aktualna wartosc .">lambda_1</a>,s_1);
<a name="l01136"></a>01136             printf(<span class="stringliteral">"C(%.2f) = %.4f\t\ts(%.2f) = %d\n"</span>,<a class="code" href="main_8c.html#d4d5373fa78e7853374abf4cd8ed277d" title="W kazdej iteracji aktualna wartosc .">lambda_2</a>,C_2,<a class="code" href="main_8c.html#d4d5373fa78e7853374abf4cd8ed277d" title="W kazdej iteracji aktualna wartosc .">lambda_2</a>,s_2);
<a name="l01137"></a>01137             printf(<span class="stringliteral">"Inicjalna poprawa L1, szukamy najmniejszej lambdy &gt; 0.\n"</span>);
<a name="l01138"></a>01138         }
<a name="l01139"></a>01139         <a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a> = <a class="code" href="main_8c.html#58222620d44f880a6aec9b6a7309f4d3" title="W kazdej iteracji aktualna wartosc .">lambda_1</a>;
<a name="l01140"></a>01140         <a class="code" href="main_8c.html#6e789198fc2fe0924eda2fd9034f520e">Sortuj</a>();
<a name="l01141"></a>01141         <a class="code" href="main_8c.html#a8e5877834c7bb319ebb1a912bcc9399" title="Poprawianie lambda w trakcie rozwiazywania relaksacji.">PoprawLambda</a>(<a class="code" href="main_8c.html#090b5d90b0350e728a076aeef5b1184b">ZNAJDZ_MIN_WIEKSZA</a>);
<a name="l01142"></a>01142         <a class="code" href="main_8c.html#58222620d44f880a6aec9b6a7309f4d3" title="W kazdej iteracji aktualna wartosc .">lambda_1</a> = <a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a>;
<a name="l01143"></a>01143 
<a name="l01144"></a>01144         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01145"></a>01145             printf(<span class="stringliteral">"\nPONOWNIE FUNKCJA RELAKSACJA.---------------------\n"</span>);
<a name="l01146"></a>01146 
<a name="l01147"></a>01147         <a class="code" href="main_8c.html#2d7e54099b87b9746019dda503574581">licznikIteracji</a> = 0;
<a name="l01148"></a>01148 
<a name="l01149"></a>01149         <span class="keywordflow">while</span> (fabs(<a class="code" href="main_8c.html#58222620d44f880a6aec9b6a7309f4d3" title="W kazdej iteracji aktualna wartosc .">lambda_1</a> - <a class="code" href="main_8c.html#d4d5373fa78e7853374abf4cd8ed277d" title="W kazdej iteracji aktualna wartosc .">lambda_2</a>)&gt;0.001) <span class="comment">// ustawiono 0.01 ze wzgledu iz dokladnosc double jest zawodna</span>
<a name="l01150"></a>01150         {
<a name="l01151"></a>01151             <a class="code" href="main_8c.html#2d7e54099b87b9746019dda503574581">licznikIteracji</a>++;
<a name="l01152"></a>01152             <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01153"></a>01153                 printf(<span class="stringliteral">"\nITERACJA NR %d.\n"</span>,<a class="code" href="main_8c.html#2d7e54099b87b9746019dda503574581">licznikIteracji</a>);
<a name="l01154"></a>01154 
<a name="l01155"></a>01155             C_1 = <a class="code" href="main_8c.html#3d9a7e827f0aea2b3b298ede3ec7427c" title="Funkcja obliczajaca C wyznacza sume x-ow (elementow, ktorym przydzielono zasob).">C</a>(<a class="code" href="main_8c.html#58222620d44f880a6aec9b6a7309f4d3" title="W kazdej iteracji aktualna wartosc .">lambda_1</a>);
<a name="l01156"></a>01156             s_1 = <a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>;
<a name="l01157"></a>01157             C_2 = <a class="code" href="main_8c.html#3d9a7e827f0aea2b3b298ede3ec7427c" title="Funkcja obliczajaca C wyznacza sume x-ow (elementow, ktorym przydzielono zasob).">C</a>(<a class="code" href="main_8c.html#d4d5373fa78e7853374abf4cd8ed277d" title="W kazdej iteracji aktualna wartosc .">lambda_2</a>);
<a name="l01158"></a>01158             s_2 = <a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>;
<a name="l01159"></a>01159 
<a name="l01160"></a>01160             <a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a> = (<a class="code" href="main_8c.html#58222620d44f880a6aec9b6a7309f4d3" title="W kazdej iteracji aktualna wartosc .">lambda_1</a>+<a class="code" href="main_8c.html#d4d5373fa78e7853374abf4cd8ed277d" title="W kazdej iteracji aktualna wartosc .">lambda_2</a>)/2;
<a name="l01161"></a>01161             <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01162"></a>01162                 printf(<span class="stringliteral">"lambda_1 = %f\tlambda_2 = %f\tlambda_s = %7.4f\n"</span>,<a class="code" href="main_8c.html#58222620d44f880a6aec9b6a7309f4d3" title="W kazdej iteracji aktualna wartosc .">lambda_1</a>,<a class="code" href="main_8c.html#d4d5373fa78e7853374abf4cd8ed277d" title="W kazdej iteracji aktualna wartosc .">lambda_2</a>,<a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a>);
<a name="l01163"></a>01163 
<a name="l01164"></a>01164             <a class="code" href="main_8c.html#3d9a7e827f0aea2b3b298ede3ec7427c" title="Funkcja obliczajaca C wyznacza sume x-ow (elementow, ktorym przydzielono zasob).">C</a>(<a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a>);
<a name="l01165"></a>01165             <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01166"></a>01166                 printf(<span class="stringliteral">"C(%.2f) = %.4f\t\ts(%.2f) = %d\n"</span>,<a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a>,<a class="code" href="main_8c.html#ba4ddc236971684b95ae11d622e50237" title="Aktualna wartosc C(  ).">aktualneC</a>,<a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a>,<a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>);
<a name="l01167"></a>01167 
<a name="l01168"></a>01168             <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#ba4ddc236971684b95ae11d622e50237" title="Aktualna wartosc C(  ).">aktualneC</a> &lt; <a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>)
<a name="l01169"></a>01169             {
<a name="l01170"></a>01170                 <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01171"></a>01171                     printf(<span class="stringliteral">" &lt; K = %d\nLambda_s zbyt duza, trzeba ja zmniejszyc.\n"</span>,<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>);
<a name="l01172"></a>01172                 <a class="code" href="main_8c.html#a8e5877834c7bb319ebb1a912bcc9399" title="Poprawianie lambda w trakcie rozwiazywania relaksacji.">PoprawLambda</a>(<a class="code" href="main_8c.html#edc0d239bfc447fb9dc15e7a96c0a19d">ZNAJDZ_MAX_MNIEJSZA</a>);
<a name="l01173"></a>01173 
<a name="l01174"></a>01174                 <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01175"></a>01175                     printf(<span class="stringliteral">"lambda_2 := lambda_s = %7.4f\n"</span>,<a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a>);
<a name="l01176"></a>01176                 <a class="code" href="main_8c.html#d4d5373fa78e7853374abf4cd8ed277d" title="W kazdej iteracji aktualna wartosc .">lambda_2</a> = <a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a>;
<a name="l01177"></a>01177             }
<a name="l01178"></a>01178             <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#ba4ddc236971684b95ae11d622e50237" title="Aktualna wartosc C(  ).">aktualneC</a> &gt; <a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>)
<a name="l01179"></a>01179             {
<a name="l01180"></a>01180                 <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01181"></a>01181                     printf(<span class="stringliteral">" &gt; K = %d\nLambda_s zbyt mala, trzeba ja zwiekszyc.\n"</span>,<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>);
<a name="l01182"></a>01182                 <a class="code" href="main_8c.html#a8e5877834c7bb319ebb1a912bcc9399" title="Poprawianie lambda w trakcie rozwiazywania relaksacji.">PoprawLambda</a>(<a class="code" href="main_8c.html#090b5d90b0350e728a076aeef5b1184b">ZNAJDZ_MIN_WIEKSZA</a>);
<a name="l01183"></a>01183 
<a name="l01184"></a>01184                 <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01185"></a>01185                     printf(<span class="stringliteral">"lambda_1 := lambda_s = %7.4f\n"</span>,<a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a>);
<a name="l01186"></a>01186                 <a class="code" href="main_8c.html#58222620d44f880a6aec9b6a7309f4d3" title="W kazdej iteracji aktualna wartosc .">lambda_1</a> = <a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a>;
<a name="l01187"></a>01187             }
<a name="l01188"></a>01188             <span class="keywordflow">else</span>
<a name="l01189"></a>01189             {
<a name="l01190"></a>01190                 <a class="code" href="main_8c.html#58222620d44f880a6aec9b6a7309f4d3" title="W kazdej iteracji aktualna wartosc .">lambda_1</a> = <a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a>;
<a name="l01191"></a>01191                 <a class="code" href="main_8c.html#d4d5373fa78e7853374abf4cd8ed277d" title="W kazdej iteracji aktualna wartosc .">lambda_2</a> = <a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a>;
<a name="l01192"></a>01192                 <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01193"></a>01193                 {
<a name="l01194"></a>01194                     printf(<span class="stringliteral">"C(lambda_s == %f) == %d == K.\n"</span>,<a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a>,<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>);
<a name="l01195"></a>01195                     printf(<span class="stringliteral">"Koniec znajdowania lambda.\n"</span>);
<a name="l01196"></a>01196                 }
<a name="l01197"></a>01197             }
<a name="l01198"></a>01198 
<a name="l01199"></a>01199             <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01200"></a>01200                 printf(<span class="stringliteral">"\n"</span>);
<a name="l01201"></a>01201         }
<a name="l01202"></a>01202 
<a name="l01203"></a>01203         <span class="comment">// lambda znaleziona, znajdzmy rozwiazanie relaksacji</span>
<a name="l01204"></a>01204         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01205"></a>01205             printf(<span class="stringliteral">"Lambda znaleziona = %f\n"</span>,<a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a>);
<a name="l01206"></a>01206         <a class="code" href="main_8c.html#e0efa66f476cffdfc64cb39068721c92" title="Funkcja aktualizuje wartosci  oraz  w wektorach na podstawie aktualnej wartosci ...">AktualizujZredukowaneWagi</a>();
<a name="l01207"></a>01207         <a class="code" href="main_8c.html#6e789198fc2fe0924eda2fd9034f520e">Sortuj</a>();
<a name="l01208"></a>01208         <a class="code" href="main_8c.html#839a6caa67dc71f4f5b8502ae6d3e3f9" title="Funkcja znajduje rozwiazanie problemu tzw. metoda zachlanna.">AlokujZachlannie</a>();
<a name="l01209"></a>01209 
<a name="l01210"></a>01210         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01211"></a>01211         {
<a name="l01212"></a>01212             printf(<span class="stringliteral">"Po znalezieniu lambda:\n"</span>);
<a name="l01213"></a>01213             <a class="code" href="main_8c.html#644a6088014dbafc3c8055c4801a9a7b">WypiszWektory</a>(<a class="code" href="main_8h.html#13b3446f7260cfaa3b9d96fcb961bcc2">MSK_ALL</a>,<a class="code" href="main_8h.html#f2c5fd4a2157bbaddee5c93c0cbebb2f">SORT_K</a>);
<a name="l01214"></a>01214             printf(<span class="stringliteral">"Aktualne C = %f, s = %d, natomiast K = %d.\n\n"</span>,<a class="code" href="main_8c.html#ba4ddc236971684b95ae11d622e50237" title="Aktualna wartosc C(  ).">aktualneC</a>,<a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>,<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>);
<a name="l01215"></a>01215         }
<a name="l01216"></a>01216 
<a name="l01217"></a>01217         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#ba4ddc236971684b95ae11d622e50237" title="Aktualna wartosc C(  ).">aktualneC</a> &gt;= <a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>)
<a name="l01218"></a>01218         {
<a name="l01219"></a>01219             printf(<span class="stringliteral">"Poniewaz C &gt;= K, koniec.\n"</span>);
<a name="l01220"></a>01220             <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>; i++)
<a name="l01221"></a>01221                 <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[i]] = 1;
<a name="l01222"></a>01222             <span class="keywordflow">for</span> (i=<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>+1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l01223"></a>01223                 <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[i]] = 0;
<a name="l01224"></a>01224         }
<a name="l01225"></a>01225 
<a name="l01226"></a>01226         <span class="keywordflow">else</span> <span class="comment">//aktualneC &lt; K</span>
<a name="l01227"></a>01227         {
<a name="l01228"></a>01228             <span class="keywordtype">int</span> U[<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>], S[<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>], R[<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>]; <span class="comment">//</span>
<a name="l01229"></a>01229             <span class="keywordtype">int</span> j,u,koniec_s,K_prim;
<a name="l01230"></a>01230 
<a name="l01231"></a>01231             <span class="comment">//double Cj[N];</span>
<a name="l01232"></a>01232             <a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a> = <a class="code" href="main_8c.html#4e1e0e72dd773439e333c84dd762a9c3" title="Maksymalna wielkosc alokacji zasobow.">c</a>;
<a name="l01233"></a>01233             <span class="keywordtype">double</span> zasob_bez_u = <a class="code" href="main_8c.html#4e1e0e72dd773439e333c84dd762a9c3" title="Maksymalna wielkosc alokacji zasobow.">c</a>;
<a name="l01234"></a>01234             <a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a> = <a class="code" href="main_8c.html#4e1e0e72dd773439e333c84dd762a9c3" title="Maksymalna wielkosc alokacji zasobow.">c</a>;
<a name="l01235"></a>01235 
<a name="l01236"></a>01236             u = 0;
<a name="l01237"></a>01237 
<a name="l01238"></a>01238             <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l01239"></a>01239             {
<a name="l01240"></a>01240                 <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#d3f87c8a272c3442f80fe3a4af4108de" title="Wektor zredukowanych dochodowosci .">v_</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[i]]&gt;<a class="code" href="main_8c.html#d3f87c8a272c3442f80fe3a4af4108de" title="Wektor zredukowanych dochodowosci .">v_</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[<a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>]])
<a name="l01241"></a>01241                 {
<a name="l01242"></a>01242                     U[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[i]] = 1;
<a name="l01243"></a>01243                     S[ik[i]] = 0;
<a name="l01244"></a>01244                     R[ik[i]] = 0;
<a name="l01245"></a>01245 
<a name="l01246"></a>01246                     <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[ik[i]] = 1;
<a name="l01247"></a>01247                     <a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a> -= <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[ik[i]];
<a name="l01248"></a>01248                     u = i;
<a name="l01249"></a>01249                 }
<a name="l01250"></a>01250                 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#d3f87c8a272c3442f80fe3a4af4108de" title="Wektor zredukowanych dochodowosci .">v_</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[i]]==<a class="code" href="main_8c.html#d3f87c8a272c3442f80fe3a4af4108de" title="Wektor zredukowanych dochodowosci .">v_</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[s]])
<a name="l01251"></a>01251                 {
<a name="l01252"></a>01252                     U[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[i]] = 0;
<a name="l01253"></a>01253                     S[ik[i]] = 1;
<a name="l01254"></a>01254                     R[ik[i]] = 0;
<a name="l01255"></a>01255 
<a name="l01256"></a>01256                     <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[ik[i]] = 0;
<a name="l01257"></a>01257                     koniec_s = i;
<a name="l01258"></a>01258                 }
<a name="l01259"></a>01259                 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#d3f87c8a272c3442f80fe3a4af4108de" title="Wektor zredukowanych dochodowosci .">v_</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[i]]&lt;<a class="code" href="main_8c.html#d3f87c8a272c3442f80fe3a4af4108de" title="Wektor zredukowanych dochodowosci .">v_</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[s]])
<a name="l01260"></a>01260                 {
<a name="l01261"></a>01261                     U[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[i]] = 0;
<a name="l01262"></a>01262                     S[ik[i]] = 0;
<a name="l01263"></a>01263                     R[ik[i]] = 1;
<a name="l01264"></a>01264 
<a name="l01265"></a>01265                     <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[ik[i]] = 0;
<a name="l01266"></a>01266                 }
<a name="l01267"></a>01267             }
<a name="l01268"></a>01268 
<a name="l01269"></a>01269 
<a name="l01270"></a>01270             zasob_bez_u = <a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a>;
<a name="l01271"></a>01271             j = u+1;
<a name="l01272"></a>01272             K_prim = <a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a> - u;
<a name="l01273"></a>01273 
<a name="l01274"></a>01274             <span class="comment">/* Definicja funkcji pomocniczej C_j */</span>
<a name="l01275"></a>01275             <span class="keywordtype">double</span> C_j(<span class="keywordtype">int</span> arg)
<a name="l01276"></a>01276             {
<a name="l01277"></a>01277                 <a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a> = zasob_bez_u;
<a name="l01278"></a>01278                 <span class="keywordtype">double</span> Cj_ = 0;
<a name="l01279"></a>01279 
<a name="l01280"></a>01280                 <span class="keywordtype">int</span> i;
<a name="l01281"></a>01281 
<a name="l01282"></a>01282                 <span class="keywordflow">for</span> (i=u+1;i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>;i++)
<a name="l01283"></a>01283                     <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[i]] = 0;
<a name="l01284"></a>01284 
<a name="l01285"></a>01285                 i = arg;
<a name="l01286"></a>01286 
<a name="l01287"></a>01287                 <span class="keywordflow">while</span> ((<a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a> &gt;= <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[i]]) &amp;&amp; (i&lt;=koniec_s))
<a name="l01288"></a>01288                 {
<a name="l01289"></a>01289                     <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[i]] = 1;
<a name="l01290"></a>01290                     <a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a> -= <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[ik[i]];
<a name="l01291"></a>01291                     Cj_ ++;
<a name="l01292"></a>01292                     i++;
<a name="l01293"></a>01293 
<a name="l01294"></a>01294                 }
<a name="l01295"></a>01295                 <span class="keywordflow">if</span> ((<a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a> &gt; 0) &amp;&amp; (i&lt;=koniec_s))
<a name="l01296"></a>01296                 {
<a name="l01297"></a>01297                     <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[i]] = (double) <a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a>/<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[ik[i]];
<a name="l01298"></a>01298                     <a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a> -= <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[ik[i]]*<a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[ik[i]];
<a name="l01299"></a>01299                     Cj_ += <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[ik[i]];
<a name="l01300"></a>01300                 }
<a name="l01301"></a>01301 
<a name="l01302"></a>01302                 <span class="keywordflow">return</span> Cj_;
<a name="l01303"></a>01303             }
<a name="l01304"></a>01304 
<a name="l01305"></a>01305             <span class="keywordtype">double</span> Cj = C_j(j);
<a name="l01306"></a>01306 
<a name="l01307"></a>01307             <span class="keywordflow">if</span> (Cj==<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>)
<a name="l01308"></a>01308                 printf(<span class="stringliteral">"hurra, zakoncz"</span>);
<a name="l01309"></a>01309 
<a name="l01310"></a>01310             <span class="keywordtype">int</span> stop = 0;
<a name="l01311"></a>01311 
<a name="l01312"></a>01312             <span class="keywordflow">while</span> (stop == 0)
<a name="l01313"></a>01313             {
<a name="l01314"></a>01314                 <span class="keywordtype">double</span> C_jp1 = C_j(j+1);
<a name="l01315"></a>01315 
<a name="l01316"></a>01316                 <span class="keywordflow">for</span> (i=j;i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l01317"></a>01317                     <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[i]] = 0;
<a name="l01318"></a>01318 
<a name="l01319"></a>01319                 <span class="keywordflow">if</span> ((C_jp1&gt;=K_prim))
<a name="l01320"></a>01320                 {
<a name="l01321"></a>01321                     <a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a> = zasob_bez_u;
<a name="l01322"></a>01322                     <span class="keywordflow">for</span> (i=j+1;i&lt;(j+K_prim);i++)
<a name="l01323"></a>01323                     {
<a name="l01324"></a>01324                         <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[i]] = 1;
<a name="l01325"></a>01325                         <a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a> -= <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[ik[i]];
<a name="l01326"></a>01326                     }
<a name="l01327"></a>01327 
<a name="l01328"></a>01328                     <span class="keywordtype">int</span> a = <a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[j];
<a name="l01329"></a>01329                     <span class="keywordtype">int</span> b = <a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[j+K_prim];
<a name="l01330"></a>01330 
<a name="l01331"></a>01331                     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[a] != <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[b])
<a name="l01332"></a>01332                     {
<a name="l01333"></a>01333                         <span class="keywordtype">double</span> licznik = (double) <a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a>-<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[a];
<a name="l01334"></a>01334                         <span class="keywordtype">double</span> mianown = (double) <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[b]-<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[a];
<a name="l01335"></a>01335 
<a name="l01336"></a>01336                         <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[b] = (double) licznik/mianown;
<a name="l01337"></a>01337                         <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[a] = 1-<a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[b];
<a name="l01338"></a>01338                     }
<a name="l01339"></a>01339                     <span class="keywordflow">else</span>
<a name="l01340"></a>01340                     {
<a name="l01341"></a>01341                         <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[a] = (double) <a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a>/<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[a];
<a name="l01342"></a>01342                         <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[b] = 0;
<a name="l01343"></a>01343                     }
<a name="l01344"></a>01344 
<a name="l01345"></a>01345                     stop = 1;
<a name="l01346"></a>01346                 }
<a name="l01347"></a>01347                 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (C_jp1 &lt; K_prim)
<a name="l01348"></a>01348                     j++;
<a name="l01349"></a>01349             }
<a name="l01350"></a>01350             <a class="code" href="main_8c.html#a5c3bae27b8fe935fe170a47139f65c2" title="Na podstawie wartosci wektora  oblicza wartosc alokacji oraz wolny zasob.">ObliczStanAlokacji</a>();
<a name="l01351"></a>01351         }
<a name="l01352"></a>01352     }
<a name="l01353"></a>01353     <a class="code" href="main_8c.html#a5c3bae27b8fe935fe170a47139f65c2" title="Na podstawie wartosci wektora  oblicza wartosc alokacji oraz wolny zasob.">ObliczStanAlokacji</a>();
<a name="l01354"></a>01354 
<a name="l01355"></a>01355     <span class="comment">//WypiszWektory(MSK_ALL,SORT_K);</span>
<a name="l01356"></a>01356 
<a name="l01357"></a>01357     <a class="code" href="main_8c.html#bc046b760068e2015d1f943257ad1c9d">wynikAlokacja</a>[<a class="code" href="main_8c.html#e41c8500c68b74939c9beab3ff16990e">REL</a>] = <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a>;
<a name="l01358"></a>01358     <a class="code" href="main_8c.html#2dc32c866ea1d483256f14beab4f0859">wynikIteracje</a>[<a class="code" href="main_8c.html#e41c8500c68b74939c9beab3ff16990e">REL</a>] = <a class="code" href="main_8c.html#2d7e54099b87b9746019dda503574581">licznikIteracji</a>;
<a name="l01359"></a>01359 
<a name="l01360"></a>01360     <span class="comment">/* ------------- zapis wynikow do pliku - wydzielic w osobnym */</span>
<a name="l01361"></a>01361     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01362"></a>01362     {
<a name="l01363"></a>01363         strcpy(<a class="code" href="main_8c.html#7c91f2a453eee2b8246c3eb270920175">dodatkoweInformacje</a>,<span class="stringliteral">"REL"</span>);
<a name="l01364"></a>01364         <span class="keywordtype">char</span> nazwaPlikuRelaksacjaOut[64];
<a name="l01365"></a>01365         strcpy(nazwaPlikuRelaksacjaOut,<a class="code" href="main_8c.html#e401adba12fa394291ec56e59e8120f4">nazwaPlikuWejsciowego</a>);
<a name="l01366"></a>01366         strcat(nazwaPlikuRelaksacjaOut,<span class="stringliteral">"_RR_out"</span>);
<a name="l01367"></a>01367         <a class="code" href="main_8c.html#7ff0e94f5e3c9337353542d81db57104" title="Generuje pliki wynikowe dla odpowiednich algorytmow.">ZapiszWyniki</a>(nazwaPlikuRelaksacjaOut);
<a name="l01368"></a>01368     }
<a name="l01369"></a>01369 
<a name="l01370"></a>01370     <span class="keywordflow">return</span>;
<a name="l01371"></a>01371 }
<a name="l01372"></a>01372 
<a name="l01373"></a>01373 <span class="comment">/* ======================================================================</span>
<a name="l01374"></a>01374 <span class="comment"> *  ALGORYTM H1</span>
<a name="l01375"></a>01375 <span class="comment"> * ====================================================================== */</span>
<a name="l01380"></a><a class="code" href="main_8c.html#e85b4a7b11917a85362470a56128e990">01380</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#e85b4a7b11917a85362470a56128e990" title="Implementacja algorytmu H1 problemu KP01&amp;lt;=K.">AlgorytmH1</a>()
<a name="l01381"></a>01381 {
<a name="l01382"></a>01382 
<a name="l01383"></a>01383     <a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a> = 0;
<a name="l01384"></a>01384     <a class="code" href="main_8c.html#e0efa66f476cffdfc64cb39068721c92" title="Funkcja aktualizuje wartosci  oraz  w wektorach na podstawie aktualnej wartosci ...">AktualizujZredukowaneWagi</a>();
<a name="l01385"></a>01385 
<a name="l01386"></a>01386     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01387"></a>01387         printf(<span class="stringliteral">"ALGORYTM H1----------------------------------\n"</span>);
<a name="l01388"></a>01388 
<a name="l01389"></a>01389     <span class="comment">// AlokujZachlannie wykorzystywany jedynie do znalezienia elementu s-tego</span>
<a name="l01390"></a>01390     <span class="comment">// przypomnienie - element x_s-ty moze byc rowny 0</span>
<a name="l01391"></a>01391     <span class="comment">// definicja x_s - najmniejsze k takie, ze suma k-tych elementow przekracza pojemnosc</span>
<a name="l01392"></a>01392     <a class="code" href="main_8c.html#6e789198fc2fe0924eda2fd9034f520e">Sortuj</a>();
<a name="l01393"></a>01393     <a class="code" href="main_8c.html#839a6caa67dc71f4f5b8502ae6d3e3f9" title="Funkcja znajduje rozwiazanie problemu tzw. metoda zachlanna.">AlokujZachlannie</a>();
<a name="l01394"></a>01394     <span class="comment">// tu juz mamy obliczona wartosc 's'</span>
<a name="l01395"></a>01395     <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a> = 0;
<a name="l01396"></a>01396     <a class="code" href="main_8c.html#2d7e54099b87b9746019dda503574581">licznikIteracji</a> = 0;
<a name="l01397"></a>01397 
<a name="l01398"></a>01398     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a> &gt;= <a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>)
<a name="l01399"></a>01399     {
<a name="l01400"></a>01400         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01401"></a>01401             printf(<span class="stringliteral">"K &gt;= s, %d &gt;= %d - zatem przydzial standardowy.\n"</span>,<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>,<a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>);
<a name="l01402"></a>01402         <a class="code" href="main_8c.html#839a6caa67dc71f4f5b8502ae6d3e3f9" title="Funkcja znajduje rozwiazanie problemu tzw. metoda zachlanna.">AlokujZachlannie</a>();
<a name="l01403"></a>01403     }
<a name="l01404"></a>01404     <span class="keywordflow">else</span>
<a name="l01405"></a>01405     {
<a name="l01406"></a>01406         <span class="keywordtype">int</span> U[<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>];
<a name="l01407"></a>01407         <span class="keywordtype">double</span> sumaU = 0;       <span class="comment">// suma w[u] dla u nalezacych do U</span>
<a name="l01408"></a>01408         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01409"></a>01409             printf(<span class="stringliteral">"k &lt; s, %d &lt; %d, algorytm poprawy start\n"</span>,<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>,<a class="code" href="main_8c.html#339d22b3e442946380f98ed19e320db2" title="Element graniczny s dla danego rozwiazania.">s</a>);
<a name="l01410"></a>01410         <span class="keywordtype">int</span> i = 1;
<a name="l01411"></a>01411         <span class="keywordtype">int</span> j = <a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>+1;
<a name="l01412"></a>01412         <span class="comment">// alokacja zasobu podmiotom 1..k</span>
<a name="l01413"></a>01413         <span class="comment">// zbior U = Lk</span>
<a name="l01414"></a>01414         <span class="keywordflow">for</span> (i=1;i&lt;=<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>;i++)
<a name="l01415"></a>01415         {
<a name="l01416"></a>01416             U[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[i]] = 1;
<a name="l01417"></a>01417             <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[ik[i]] = 1;
<a name="l01418"></a>01418             <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a> += <a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[ik[i]];
<a name="l01419"></a>01419             sumaU += <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[ik[i]];
<a name="l01420"></a>01420         }
<a name="l01421"></a>01421 
<a name="l01422"></a>01422         <span class="comment">// zbior L \ Lk</span>
<a name="l01423"></a>01423         <span class="keywordflow">for</span> (i=<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>+1;i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>;i++)
<a name="l01424"></a>01424         {
<a name="l01425"></a>01425             U[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[i]] = 0;
<a name="l01426"></a>01426             <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[ik[i]] = 0;
<a name="l01427"></a>01427         }
<a name="l01428"></a>01428 
<a name="l01429"></a>01429         <span class="keywordtype">double</span> delta_z[<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>], delta_ij[<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>];
<a name="l01430"></a>01430         <a class="code" href="main_8c.html#2d7e54099b87b9746019dda503574581">licznikIteracji</a> = 1;
<a name="l01431"></a>01431         <span class="keywordflow">while</span> (j &lt; <a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a> &amp;&amp; sumaU &lt; <a class="code" href="main_8c.html#4e1e0e72dd773439e333c84dd762a9c3" title="Maksymalna wielkosc alokacji zasobow.">c</a>)
<a name="l01432"></a>01432         {
<a name="l01433"></a>01433             i = 1;
<a name="l01434"></a>01434             <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01435"></a>01435             {
<a name="l01436"></a>01436                 printf(<span class="stringliteral">"\n\nITERACJA %d. j = %d\t"</span>,<a class="code" href="main_8c.html#2d7e54099b87b9746019dda503574581">licznikIteracji</a>,j);
<a name="l01437"></a>01437                 printf(<span class="stringliteral">"Wartosc alokacji = %f\n"</span>,<a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a>);
<a name="l01438"></a>01438                 printf(<span class="stringliteral">"Zawartosc :\n"</span>);
<a name="l01439"></a>01439                 <a class="code" href="main_8c.html#644a6088014dbafc3c8055c4801a9a7b">WypiszWektory</a>(<a class="code" href="main_8h.html#58961bee5268baf32d9ca9ac51bcf126">MSK_INDEX</a>|<a class="code" href="main_8h.html#e00a20f61164fb74cb09105d2f4348c8">MSK_P</a>|<a class="code" href="main_8h.html#072e387394eca86e5be43efef72251cf">MSK_XR</a>,<a class="code" href="main_8h.html#f2c5fd4a2157bbaddee5c93c0cbebb2f">SORT_K</a>);
<a name="l01440"></a>01440                 printf(<span class="stringliteral">"\nElementy zaalokowane do utraty zasobu na rzecz x%d: "</span>,<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[j]);
<a name="l01441"></a>01441             }
<a name="l01442"></a>01442             <span class="keywordtype">int</span> brak=1;
<a name="l01443"></a>01443             <span class="keywordtype">double</span> max_delta =  -1;
<a name="l01444"></a>01444             <span class="keywordtype">int</span> max_delta_index = 1;
<a name="l01445"></a>01445             <span class="keywordflow">while</span> (i &lt;= <a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>)
<a name="l01446"></a>01446             {
<a name="l01447"></a>01447                 <span class="comment">// tylko dla zbioru U z warunkami ''polepszenia rozwiazania''</span>
<a name="l01448"></a>01448                 <span class="keywordflow">if</span> ( (U[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[i]] == 1) &amp;&amp; (<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[i]] &lt; <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[j]]) &amp;&amp; (<a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[i]] &lt; <a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[j]]) )
<a name="l01449"></a>01449                 {
<a name="l01450"></a>01450                     <span class="comment">//obliczenie delta_z[i] = pj*delta_ij - pi*xi dla kazdego elementu</span>
<a name="l01451"></a>01451                     brak = 0;
<a name="l01452"></a>01452                     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01453"></a>01453                         printf(<span class="stringliteral">"x%d "</span>,<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[i]);
<a name="l01454"></a>01454                     delta_ij[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[i]] = (double) <a class="code" href="main_8c.html#4e1e0e72dd773439e333c84dd762a9c3" title="Maksymalna wielkosc alokacji zasobow.">c</a>;
<a name="l01455"></a>01455                     <span class="keywordtype">int</span> u;
<a name="l01456"></a>01456                     <span class="keywordflow">for</span> (u=1; u&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; u++)
<a name="l01457"></a>01457                         <span class="keywordflow">if</span> (U[ik[u]]==1)
<a name="l01458"></a>01458                             delta_ij[ik[i]] -= (double) <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[ik[u]];
<a name="l01459"></a>01459 
<a name="l01460"></a>01460                     delta_ij[ik[i]] += (double) <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[ik[i]];
<a name="l01461"></a>01461                     delta_ij[ik[i]] /= (double) <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[ik[j]];
<a name="l01462"></a>01462 
<a name="l01463"></a>01463                     <span class="keywordflow">if</span> (delta_ij[ik[i]]&gt;1)
<a name="l01464"></a>01464                         delta_ij[ik[i]] = 1;
<a name="l01465"></a>01465 
<a name="l01466"></a>01466                     delta_z[ik[i]] = (double) <a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[ik[j]]*delta_ij[ik[i]] - <a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[ik[i]]*<a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[ik[i]];
<a name="l01467"></a>01467 
<a name="l01468"></a>01468                     <span class="keywordflow">if</span> (delta_z[ik[i]] &gt; max_delta)
<a name="l01469"></a>01469                     {
<a name="l01470"></a>01470                         max_delta = delta_z[ik[i]];
<a name="l01471"></a>01471                         max_delta_index = i;
<a name="l01472"></a>01472                     }
<a name="l01473"></a>01473                 }
<a name="l01474"></a>01474                 i++;
<a name="l01475"></a>01475             }
<a name="l01476"></a>01476             <span class="keywordflow">if</span> (brak)
<a name="l01477"></a>01477             {
<a name="l01478"></a>01478                 <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01479"></a>01479                     printf(<span class="stringliteral">" BRAK\n"</span>);
<a name="l01480"></a>01480             }
<a name="l01481"></a>01481             <span class="keywordflow">else</span>
<a name="l01482"></a>01482             {
<a name="l01483"></a>01483                 <span class="keywordflow">if</span> (max_delta &gt; 10E-5)
<a name="l01484"></a>01484                 {
<a name="l01485"></a>01485                     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01486"></a>01486                     {
<a name="l01487"></a>01487                         printf(<span class="stringliteral">"\nNajwiekszy przyrost zysku dla elementu x%d delta_z = %f\n"</span>,<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[max_delta_index],max_delta);
<a name="l01488"></a>01488 
<a name="l01489"></a>01489                         printf(<span class="stringliteral">"x%d = %d\t"</span>,<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[max_delta_index],0);
<a name="l01490"></a>01490                         printf(<span class="stringliteral">"x%d = %f\n"</span>,<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[j],delta_ij[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[max_delta_index]]);
<a name="l01491"></a>01491                     }
<a name="l01492"></a>01492                     <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a> -= <a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[max_delta_index]]*<a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[max_delta_index]];
<a name="l01493"></a>01493                     <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a> += <a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[ik[j]]*delta_ij[ik[max_delta_index]];
<a name="l01494"></a>01494 
<a name="l01495"></a>01495                     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01496"></a>01496                         printf(<span class="stringliteral">"Nowa wartosc zaalokowanych zasobow : z = %f "</span>,<a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a>);
<a name="l01497"></a>01497 
<a name="l01498"></a>01498                     <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[ik[max_delta_index]] = 0;
<a name="l01499"></a>01499                     <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[ik[j]] = delta_ij[ik[max_delta_index]];
<a name="l01500"></a>01500 
<a name="l01501"></a>01501                     U[ik[max_delta_index]] = 0;
<a name="l01502"></a>01502                     sumaU -= <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[ik[max_delta_index]];
<a name="l01503"></a>01503                     U[ik[j]] = 1;
<a name="l01504"></a>01504                     sumaU += <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[ik[j]];
<a name="l01505"></a>01505                 }
<a name="l01506"></a>01506             }
<a name="l01507"></a>01507             <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01508"></a>01508                 printf(<span class="stringliteral">"suma u = %f"</span>,sumaU);
<a name="l01509"></a>01509 
<a name="l01510"></a>01510             j++;
<a name="l01511"></a>01511             <a class="code" href="main_8c.html#2d7e54099b87b9746019dda503574581">licznikIteracji</a>++;
<a name="l01512"></a>01512         }
<a name="l01513"></a>01513 
<a name="l01514"></a>01514         <a class="code" href="main_8c.html#bc046b760068e2015d1f943257ad1c9d">wynikAlokacja</a>[<a class="code" href="main_8c.html#3e4baeb2553d751ae0c007569655a137">H1</a>] = <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a>;
<a name="l01515"></a>01515         <a class="code" href="main_8c.html#2dc32c866ea1d483256f14beab4f0859">wynikIteracje</a>[<a class="code" href="main_8c.html#3e4baeb2553d751ae0c007569655a137">H1</a>] = <a class="code" href="main_8c.html#2d7e54099b87b9746019dda503574581">licznikIteracji</a>;
<a name="l01516"></a>01516 
<a name="l01517"></a>01517         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01518"></a>01518         {
<a name="l01519"></a>01519             <span class="keywordtype">char</span> nazwaPlikuH1Out[64];
<a name="l01520"></a>01520             strcpy(nazwaPlikuH1Out,<a class="code" href="main_8c.html#e13ce79999caa4f4e3e787ee9a17ec0e">nazwaProblemu</a>);
<a name="l01521"></a>01521             strcat(nazwaPlikuH1Out,<span class="stringliteral">"_H1.out"</span>);
<a name="l01522"></a>01522             strcpy(<a class="code" href="main_8c.html#7c91f2a453eee2b8246c3eb270920175">dodatkoweInformacje</a>,<span class="stringliteral">"H1"</span>);
<a name="l01523"></a>01523             <a class="code" href="main_8c.html#7ff0e94f5e3c9337353542d81db57104" title="Generuje pliki wynikowe dla odpowiednich algorytmow.">ZapiszWyniki</a>(nazwaPlikuH1Out);
<a name="l01524"></a>01524         }
<a name="l01525"></a>01525     }
<a name="l01526"></a>01526 }
<a name="l01527"></a>01527 
<a name="l01528"></a>01528 <span class="comment">/* ======================================================================</span>
<a name="l01529"></a>01529 <span class="comment"> *  ALGORYTM H2</span>
<a name="l01530"></a>01530 <span class="comment"> * ====================================================================== */</span>
<a name="l01547"></a><a class="code" href="main_8c.html#7afb6457bc15f6a1fea27f461601e850">01547</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#7afb6457bc15f6a1fea27f461601e850" title="Implementacja algorytmu H2 problemu KP01&amp;lt;=K.">AlgorytmH2</a>()
<a name="l01548"></a>01548 {
<a name="l01549"></a>01549 
<a name="l01550"></a>01550 
<a name="l01551"></a>01551     <a class="code" href="main_8c.html#86892a380cb93ebd030dba5a6302be06" title="Inicjalizuje czesc wektorow.">InicjujDane</a>();
<a name="l01552"></a>01552     <a class="code" href="main_8c.html#cdd4e11b1fc38e16d036b25d02df00f0" title="Implementacja rozwiazania zrelaksowanego problemu KP01&amp;lt;=K.">Relaksacja</a>();
<a name="l01553"></a>01553     <a class="code" href="main_8c.html#2d7e54099b87b9746019dda503574581">licznikIteracji</a> = 0;
<a name="l01554"></a>01554 
<a name="l01555"></a>01555     <span class="comment">// jesli co najwyzej K dodatnich x-ow to koniec - zaimplementowac warunek</span>
<a name="l01556"></a>01556     <span class="keywordtype">int</span> ileDodatnichX = 0;
<a name="l01557"></a>01557     <span class="keywordtype">int</span> i;
<a name="l01558"></a>01558     <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l01559"></a>01559         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[i]&gt;0.0001)
<a name="l01560"></a>01560             ileDodatnichX++;
<a name="l01561"></a>01561 
<a name="l01562"></a>01562     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01563"></a>01563         printf(<span class="stringliteral">"%d dodatnich x-ow, zatem "</span>,ileDodatnichX);
<a name="l01564"></a>01564 
<a name="l01565"></a>01565     <span class="keywordflow">if</span> (ileDodatnichX &lt;= <a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>)
<a name="l01566"></a>01566     {
<a name="l01567"></a>01567         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01568"></a>01568             printf(<span class="stringliteral">"koniec.\n"</span>);
<a name="l01569"></a>01569     }
<a name="l01570"></a>01570 
<a name="l01571"></a>01571     <span class="keywordflow">else</span> <span class="comment">// liczba dodatnich x-ow &gt; K</span>
<a name="l01572"></a>01572     {
<a name="l01573"></a>01573         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01574"></a>01574             printf(<span class="stringliteral">"algorytm poprawy H2.\n"</span>);
<a name="l01575"></a>01575         <a class="code" href="main_8c.html#2d7e54099b87b9746019dda503574581">licznikIteracji</a> = 1;
<a name="l01576"></a>01576 
<a name="l01577"></a>01577         <span class="comment">// jesli K+1 dodatnich x-ow</span>
<a name="l01578"></a>01578         <span class="keywordtype">int</span> i_a = <a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>];        <span class="comment">//indeksy zgodnie z nomenklatura "i"</span>
<a name="l01579"></a>01579         <span class="keywordtype">int</span> i_b = <a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>+1];
<a name="l01580"></a>01580 
<a name="l01581"></a>01581         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[i_a] &gt; <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[i_b])
<a name="l01582"></a>01582         {
<a name="l01583"></a>01583             <span class="keywordtype">int</span> tmp;
<a name="l01584"></a>01584             tmp = i_a;
<a name="l01585"></a>01585             i_a = i_b;
<a name="l01586"></a>01586             i_b = tmp;
<a name="l01587"></a>01587         }
<a name="l01588"></a>01588         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01589"></a>01589             printf(<span class="stringliteral">"i_a = %d, i_b = %d\n"</span>,i_a,i_b);
<a name="l01590"></a>01590 
<a name="l01591"></a>01591         <span class="comment">// wiadomo ze w[i_a] &lt;= w[i_b]</span>
<a name="l01592"></a>01592 
<a name="l01593"></a>01593         <span class="keywordtype">double</span> rozw1 = <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a> - (<a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[i_b]*<a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[i_b]+<a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[i_a]*<a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[i_a]);       <span class="comment">// rozwiazanie x'</span>
<a name="l01594"></a>01594         <span class="keywordtype">double</span> rozw2 = rozw1;
<a name="l01595"></a>01595 
<a name="l01596"></a>01596         <span class="comment">// rozw1 = J + {a}</span>
<a name="l01597"></a>01597         rozw1 += <a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[i_a];
<a name="l01598"></a>01598 
<a name="l01599"></a>01599         <span class="comment">// rozw2 = J + czesc {b}</span>
<a name="l01600"></a>01600         <span class="keywordtype">double</span> wolne = <a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a>+(<a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[i_b]*<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[i_b]+<a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[i_a]*<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[i_a]);
<a name="l01601"></a>01601         <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[i_b] = (double) wolne/<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[i_b];
<a name="l01602"></a>01602         rozw2 += xr[i_b]*<a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[i_b];
<a name="l01603"></a>01603 
<a name="l01604"></a>01604         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01605"></a>01605             printf(<span class="stringliteral">"Lepsze rozwiazanie "</span>);
<a name="l01606"></a>01606 
<a name="l01607"></a>01607         <span class="keywordflow">if</span> (rozw1 &gt; rozw2)
<a name="l01608"></a>01608         {
<a name="l01609"></a>01609             <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01610"></a>01610                 printf(<span class="stringliteral">"to x', rowne %f.\n"</span>,rozw1);
<a name="l01611"></a>01611             xr[i_a] = 1;
<a name="l01612"></a>01612             xr[i_b] = 0;
<a name="l01613"></a>01613         }
<a name="l01614"></a>01614         <span class="keywordflow">else</span> <span class="comment">// (rozw1 &lt;= rozw2)</span>
<a name="l01615"></a>01615         {
<a name="l01616"></a>01616             <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01617"></a>01617                 printf(<span class="stringliteral">"to x\", rowne %f.\n"</span>,rozw2);
<a name="l01618"></a>01618             xr[i_a] = 0;
<a name="l01619"></a>01619         }
<a name="l01620"></a>01620         <a class="code" href="main_8c.html#a5c3bae27b8fe935fe170a47139f65c2" title="Na podstawie wartosci wektora  oblicza wartosc alokacji oraz wolny zasob.">ObliczStanAlokacji</a>();
<a name="l01621"></a>01621     }
<a name="l01622"></a>01622 
<a name="l01623"></a>01623     <a class="code" href="main_8c.html#bc046b760068e2015d1f943257ad1c9d">wynikAlokacja</a>[<a class="code" href="main_8c.html#b5e8a97982062958fb8f58a428df09ee">H2</a>] = <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a>;
<a name="l01624"></a>01624     <a class="code" href="main_8c.html#2dc32c866ea1d483256f14beab4f0859">wynikIteracje</a>[<a class="code" href="main_8c.html#b5e8a97982062958fb8f58a428df09ee">H2</a>] = <a class="code" href="main_8c.html#2d7e54099b87b9746019dda503574581">licznikIteracji</a>;
<a name="l01625"></a>01625 
<a name="l01626"></a>01626     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01627"></a>01627     {
<a name="l01628"></a>01628         strcpy(<a class="code" href="main_8c.html#7c91f2a453eee2b8246c3eb270920175">dodatkoweInformacje</a>,<span class="stringliteral">"H2"</span>);
<a name="l01629"></a>01629         <span class="keywordtype">char</span> nazwaPlikuH2Out[64];
<a name="l01630"></a>01630         strcpy(nazwaPlikuH2Out,<a class="code" href="main_8c.html#e401adba12fa394291ec56e59e8120f4">nazwaPlikuWejsciowego</a>);
<a name="l01631"></a>01631         strcat(nazwaPlikuH2Out,<span class="stringliteral">"_H2_out"</span>);
<a name="l01632"></a>01632         <a class="code" href="main_8c.html#7ff0e94f5e3c9337353542d81db57104" title="Generuje pliki wynikowe dla odpowiednich algorytmow.">ZapiszWyniki</a>(nazwaPlikuH2Out);
<a name="l01633"></a>01633     }
<a name="l01634"></a>01634 }
<a name="l01635"></a>01635 
<a name="l01636"></a>01636 <span class="comment">/* ======================================================================</span>
<a name="l01637"></a>01637 <span class="comment"> *  ALGORYTM H2 PRIM</span>
<a name="l01638"></a>01638 <span class="comment"> * ====================================================================== */</span>
<a name="l01646"></a><a class="code" href="main_8c.html#c7f7228e325a7bc232d8940ccec07979">01646</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#c7f7228e325a7bc232d8940ccec07979" title="Implementacja algorytmu H2&amp;#39; problemu KP01&amp;lt;=K.">AlgorytmH2Prim</a>()
<a name="l01647"></a>01647 {
<a name="l01648"></a>01648     strcpy(<a class="code" href="main_8c.html#7c91f2a453eee2b8246c3eb270920175">dodatkoweInformacje</a>,<span class="stringliteral">"H2\'"</span>);
<a name="l01649"></a>01649 
<a name="l01650"></a>01650     <a class="code" href="main_8c.html#86892a380cb93ebd030dba5a6302be06" title="Inicjalizuje czesc wektorow.">InicjujDane</a>();
<a name="l01651"></a>01651     <a class="code" href="main_8c.html#cdd4e11b1fc38e16d036b25d02df00f0" title="Implementacja rozwiazania zrelaksowanego problemu KP01&amp;lt;=K.">Relaksacja</a>();
<a name="l01652"></a>01652     <a class="code" href="main_8c.html#2d7e54099b87b9746019dda503574581">licznikIteracji</a> = 0;
<a name="l01653"></a>01653 
<a name="l01654"></a>01654     <span class="comment">// jesli co najwyzej K dodatnich x-ow to koniec - zaimplementowac warunek</span>
<a name="l01655"></a>01655     <span class="keywordtype">int</span> ileDodatnichX = 0;
<a name="l01656"></a>01656     <span class="keywordtype">int</span> i;
<a name="l01657"></a>01657 
<a name="l01658"></a>01658     <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l01659"></a>01659     {
<a name="l01660"></a>01660         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[i]&gt;0.0001)
<a name="l01661"></a>01661             ileDodatnichX++;
<a name="l01662"></a>01662         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[i]&lt;1)
<a name="l01663"></a>01663         {
<a name="l01664"></a>01664             <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[i] = 0;
<a name="l01665"></a>01665         }
<a name="l01666"></a>01666     }
<a name="l01667"></a>01667 
<a name="l01668"></a>01668     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01669"></a>01669 
<a name="l01670"></a>01670         printf(<span class="stringliteral">"%d dodatnich x-ow, zatem "</span>,ileDodatnichX);
<a name="l01671"></a>01671 
<a name="l01672"></a>01672     <span class="keywordflow">if</span> (ileDodatnichX &lt;= <a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>)
<a name="l01673"></a>01673     {
<a name="l01674"></a>01674         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01675"></a>01675             printf(<span class="stringliteral">"koniec.\n"</span>);
<a name="l01676"></a>01676     }
<a name="l01677"></a>01677     <span class="keywordflow">else</span> <span class="comment">// liczba dodatnich x-ow &gt; K</span>
<a name="l01678"></a>01678     {
<a name="l01679"></a>01679         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01680"></a>01680             printf(<span class="stringliteral">"algorytm poprawy H2'.\n"</span>);
<a name="l01681"></a>01681         <a class="code" href="main_8c.html#2d7e54099b87b9746019dda503574581">licznikIteracji</a> = 1;
<a name="l01682"></a>01682         <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l01683"></a>01683             <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[i]&lt;1)
<a name="l01684"></a>01684                 <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[i] = 0;
<a name="l01685"></a>01685         <a class="code" href="main_8c.html#a5c3bae27b8fe935fe170a47139f65c2" title="Na podstawie wartosci wektora  oblicza wartosc alokacji oraz wolny zasob.">ObliczStanAlokacji</a>();
<a name="l01686"></a>01686 
<a name="l01687"></a>01687         <span class="keywordtype">double</span> najwiekszyZysk = -1;
<a name="l01688"></a>01688         <span class="keywordtype">int</span> i_najlepszy;
<a name="l01689"></a>01689 
<a name="l01690"></a>01690         <span class="keywordflow">for</span> (i=1;i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>;i++)
<a name="l01691"></a>01691         {
<a name="l01692"></a>01692             <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[i] == 0)
<a name="l01693"></a>01693             {
<a name="l01694"></a>01694                 <span class="keywordtype">double</span> zysk_i;
<a name="l01695"></a>01695                 <span class="keywordtype">double</span> x_i;
<a name="l01696"></a>01696 
<a name="l01697"></a>01697                 x_i = <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[i] &gt; <a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a> ? <a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a>/<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[i] : 1;
<a name="l01698"></a>01698                 zysk_i = x_i * <a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[i];
<a name="l01699"></a>01699                 <span class="keywordflow">if</span> (zysk_i &gt; najwiekszyZysk)
<a name="l01700"></a>01700                 {
<a name="l01701"></a>01701                     najwiekszyZysk = zysk_i;
<a name="l01702"></a>01702                     i_najlepszy = i;
<a name="l01703"></a>01703                 }
<a name="l01704"></a>01704             }
<a name="l01705"></a>01705         }
<a name="l01706"></a>01706         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01707"></a>01707             printf(<span class="stringliteral">"Najlepszy zysk = %f dla x%d.\n"</span>,najwiekszyZysk,i_najlepszy);
<a name="l01708"></a>01708         <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[i_najlepszy] = 1;
<a name="l01709"></a>01709 
<a name="l01710"></a>01710         <a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a> = 0;
<a name="l01711"></a>01711         <a class="code" href="main_8c.html#6e789198fc2fe0924eda2fd9034f520e">Sortuj</a>();
<a name="l01712"></a>01712 
<a name="l01713"></a>01713         <a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a> = <a class="code" href="main_8c.html#4e1e0e72dd773439e333c84dd762a9c3" title="Maksymalna wielkosc alokacji zasobow.">c</a>;
<a name="l01714"></a>01714         <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a> = 0;
<a name="l01715"></a>01715 
<a name="l01716"></a>01716         <span class="keywordtype">int</span> j = 1;
<a name="l01717"></a>01717 
<a name="l01718"></a>01718         <span class="keywordflow">while</span> (<a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a> &gt; 0 &amp;&amp; j &lt;= <a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>)
<a name="l01719"></a>01719         {
<a name="l01720"></a>01720             <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[j]]&gt;0)
<a name="l01721"></a>01721             {   <span class="comment">// tylko dla zbioru J + {i}</span>
<a name="l01722"></a>01722                 <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a> &gt;= <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[j]])
<a name="l01723"></a>01723                 {
<a name="l01724"></a>01724                     <a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a> -= <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[j]];
<a name="l01725"></a>01725                     <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a> += (double) <a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[ik[j]];
<a name="l01726"></a>01726                     <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[ik[j]] = 1;
<a name="l01727"></a>01727                 }
<a name="l01728"></a>01728                 <span class="keywordflow">else</span>
<a name="l01729"></a>01729                 {
<a name="l01730"></a>01730                     <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[j]] = <a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a>/<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[ik[j]];
<a name="l01731"></a>01731                     <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a> += (double) <a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[ik[j]]*<a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[ik[j]];
<a name="l01732"></a>01732                     <a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a> = 0;
<a name="l01733"></a>01733                 }
<a name="l01734"></a>01734             }
<a name="l01735"></a>01735             j++;
<a name="l01736"></a>01736         }
<a name="l01737"></a>01737     }
<a name="l01738"></a>01738 
<a name="l01739"></a>01739 
<a name="l01740"></a>01740     <a class="code" href="main_8c.html#bc046b760068e2015d1f943257ad1c9d">wynikAlokacja</a>[<a class="code" href="main_8c.html#e3ea6c504e916b75b4e44abeffdb8477">H2P</a>] = <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a>;
<a name="l01741"></a>01741     <a class="code" href="main_8c.html#2dc32c866ea1d483256f14beab4f0859">wynikIteracje</a>[<a class="code" href="main_8c.html#e3ea6c504e916b75b4e44abeffdb8477">H2P</a>] = <a class="code" href="main_8c.html#2d7e54099b87b9746019dda503574581">licznikIteracji</a>;
<a name="l01742"></a>01742 
<a name="l01743"></a>01743     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01744"></a>01744     {
<a name="l01745"></a>01745         <span class="keywordtype">char</span> nazwaPlikuH2pOut[64];
<a name="l01746"></a>01746         strcpy(nazwaPlikuH2pOut,<a class="code" href="main_8c.html#e401adba12fa394291ec56e59e8120f4">nazwaPlikuWejsciowego</a>);
<a name="l01747"></a>01747         strcat(nazwaPlikuH2pOut,<span class="stringliteral">"_H2p_out"</span>);
<a name="l01748"></a>01748         <a class="code" href="main_8c.html#7ff0e94f5e3c9337353542d81db57104" title="Generuje pliki wynikowe dla odpowiednich algorytmow.">ZapiszWyniki</a>(nazwaPlikuH2pOut);
<a name="l01749"></a>01749     }
<a name="l01750"></a>01750 }
<a name="l01751"></a>01751 
<a name="l01752"></a>01752 <span class="comment">/* ======================================================================</span>
<a name="l01753"></a>01753 <span class="comment"> *  ALGORYTM H2 BIS</span>
<a name="l01754"></a>01754 <span class="comment"> * ====================================================================== */</span>
<a name="l01764"></a><a class="code" href="main_8c.html#779e9c536e6db05731f94e52eabadfdd">01764</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#779e9c536e6db05731f94e52eabadfdd" title="Implementacja algorytmu H2 BIS problemu KP01&amp;lt;=K.">AlgorytmH2Bis</a>()
<a name="l01765"></a>01765 {
<a name="l01766"></a>01766 
<a name="l01767"></a>01767     <a class="code" href="main_8c.html#86892a380cb93ebd030dba5a6302be06" title="Inicjalizuje czesc wektorow.">InicjujDane</a>();
<a name="l01768"></a>01768     <a class="code" href="main_8c.html#cdd4e11b1fc38e16d036b25d02df00f0" title="Implementacja rozwiazania zrelaksowanego problemu KP01&amp;lt;=K.">Relaksacja</a>();
<a name="l01769"></a>01769     <a class="code" href="main_8c.html#2d7e54099b87b9746019dda503574581">licznikIteracji</a> = 0;
<a name="l01770"></a>01770     <a class="code" href="main_8c.html#3db359547eed8cfd48ca821d95f577af" title="W kazdej iteracji aktualna wartosc .">lambda</a> = 0;
<a name="l01771"></a>01771 
<a name="l01772"></a>01772     <span class="comment">// jesli co najwyzej K dodatnich x-ow to koniec - zaimplementowac warunek</span>
<a name="l01773"></a>01773     <span class="keywordtype">int</span> ileDodatnichX = 0;
<a name="l01774"></a>01774     <span class="keywordtype">int</span> i;
<a name="l01775"></a>01775     <span class="keywordtype">int</span> L[<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>];
<a name="l01776"></a>01776 
<a name="l01777"></a>01777     <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l01778"></a>01778     {
<a name="l01779"></a>01779         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#cb7abbc9f401e8f4b2d138d6eaba3909" title="Rozwiazanie problemu wybranym algorytmem.">xr</a>[i]&gt;10e-6)
<a name="l01780"></a>01780         {
<a name="l01781"></a>01781             ileDodatnichX++;
<a name="l01782"></a>01782             L[i] = 1;
<a name="l01783"></a>01783         }
<a name="l01784"></a>01784         <span class="keywordflow">else</span>
<a name="l01785"></a>01785             L[i] = 0;
<a name="l01786"></a>01786     }
<a name="l01787"></a>01787 
<a name="l01788"></a>01788     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01789"></a>01789         printf(<span class="stringliteral">"%d dodatnich x-ow, zatem "</span>,ileDodatnichX);
<a name="l01790"></a>01790 
<a name="l01791"></a>01791     <span class="keywordflow">if</span> (ileDodatnichX &lt;= <a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>)
<a name="l01792"></a>01792     {
<a name="l01793"></a>01793         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01794"></a>01794             printf(<span class="stringliteral">"koniec.\n"</span>);
<a name="l01795"></a>01795 
<a name="l01796"></a>01796     }
<a name="l01797"></a>01797 
<a name="l01798"></a>01798     <span class="keywordflow">else</span> <span class="comment">// liczba dodatnich x-ow &gt; K</span>
<a name="l01799"></a>01799     {
<a name="l01800"></a>01800         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01801"></a>01801             printf(<span class="stringliteral">"algorytm poprawy H2\".\n"</span>);
<a name="l01802"></a>01802         <a class="code" href="main_8c.html#2d7e54099b87b9746019dda503574581">licznikIteracji</a> = 1;
<a name="l01803"></a>01803         <span class="keywordtype">int</span> j;
<a name="l01804"></a>01804 
<a name="l01805"></a>01805         <span class="keywordtype">double</span> najlepszyPrzydzial = 0;
<a name="l01806"></a>01806         <span class="comment">// int ktoryUsunac = 0;</span>
<a name="l01807"></a>01807         <a class="code" href="main_8c.html#6e789198fc2fe0924eda2fd9034f520e">Sortuj</a>();
<a name="l01808"></a>01808 
<a name="l01809"></a>01809         <span class="keywordflow">for</span> (j=1; j&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; j++) <span class="comment">// dla kazdego j nalezacego do L</span>
<a name="l01810"></a>01810             <span class="keywordflow">if</span> (L[j]==1)
<a name="l01811"></a>01811             {
<a name="l01812"></a>01812                 L[j] = 0;
<a name="l01813"></a>01813 
<a name="l01814"></a>01814                 <a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a> = <a class="code" href="main_8c.html#4e1e0e72dd773439e333c84dd762a9c3" title="Maksymalna wielkosc alokacji zasobow.">c</a>;
<a name="l01815"></a>01815                 <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a> = 0;
<a name="l01816"></a>01816                 <span class="keywordtype">int</span> k=0;
<a name="l01817"></a>01817                 <span class="keywordflow">while</span> (k&lt;<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>)
<a name="l01818"></a>01818                 {
<a name="l01819"></a>01819                     k++;
<a name="l01820"></a>01820                     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[k]] &lt;= <a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a> &amp;&amp; L[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[k]] == 1)
<a name="l01821"></a>01821                     {
<a name="l01822"></a>01822                         <a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a> -= <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[k]];
<a name="l01823"></a>01823                         <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a> += <a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[ik[k]];
<a name="l01824"></a>01824                         <span class="comment">//printf("bez %d alokacja w calosci %d\n",j,ik[k]);</span>
<a name="l01825"></a>01825                     }
<a name="l01826"></a>01826                     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[k]] &gt; <a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a> &amp;&amp; L[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[k]] == 1)
<a name="l01827"></a>01827                     {
<a name="l01828"></a>01828                         <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a> += <a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[k]]*(<a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a>/<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[k]]);
<a name="l01829"></a>01829                         <a class="code" href="main_8c.html#f136cf7e3358a038a3e1dde5d7e23410" title="Wolny, nieprzydzielony zasob.">wolnyZasob</a> = 0;
<a name="l01830"></a>01830                         <span class="comment">//printf("bez %d alokacja czesciowa %d\n",j,ik[k]);</span>
<a name="l01831"></a>01831                         <span class="keywordflow">break</span>;
<a name="l01832"></a>01832                     }
<a name="l01833"></a>01833                     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (L[<a class="code" href="main_8c.html#832dbd00bd37a8ef42a94ef109ad6b35" title="Wektor okreslajacy indeks k-tego podmiotu (pod wgledem dochodowosci  ).">ik</a>[k]]==0)
<a name="l01834"></a>01834                         <span class="keywordflow">continue</span>;
<a name="l01835"></a>01835                 }
<a name="l01836"></a>01836                 <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01837"></a>01837                     printf(<span class="stringliteral">"alokacja bez %d elementu rowna %f\n"</span>,j,<a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a>);
<a name="l01838"></a>01838                 najlepszyPrzydzial = <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a> &gt; najlepszyPrzydzial ? <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a> : najlepszyPrzydzial;
<a name="l01839"></a>01839                 L[j] = 1;
<a name="l01840"></a>01840             }
<a name="l01841"></a>01841         <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a> = najlepszyPrzydzial;
<a name="l01842"></a>01842     }
<a name="l01843"></a>01843 
<a name="l01844"></a>01844     <a class="code" href="main_8c.html#bc046b760068e2015d1f943257ad1c9d">wynikAlokacja</a>[<a class="code" href="main_8c.html#13ba4f47dcd4f3e4a0dca6330c1916f2">H2B</a>] = <a class="code" href="main_8c.html#48a2047bb958d9ab7a589c0402694e90" title="Wartosc aktualnej alokacji (na podstawie wektora xr).">wartoscAlokacji</a>;
<a name="l01845"></a>01845     <a class="code" href="main_8c.html#2dc32c866ea1d483256f14beab4f0859">wynikIteracje</a>[<a class="code" href="main_8c.html#13ba4f47dcd4f3e4a0dca6330c1916f2">H2B</a>] = <a class="code" href="main_8c.html#2d7e54099b87b9746019dda503574581">licznikIteracji</a>;
<a name="l01846"></a>01846 
<a name="l01847"></a>01847     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01848"></a>01848     {
<a name="l01849"></a>01849         <span class="keywordtype">char</span> nazwaPlikuH2bisOut[64];
<a name="l01850"></a>01850         strcpy(nazwaPlikuH2bisOut,<a class="code" href="main_8c.html#e401adba12fa394291ec56e59e8120f4">nazwaPlikuWejsciowego</a>);
<a name="l01851"></a>01851         strcat(nazwaPlikuH2bisOut,<span class="stringliteral">"_H2b_out"</span>);
<a name="l01852"></a>01852         strcpy(<a class="code" href="main_8c.html#7c91f2a453eee2b8246c3eb270920175">dodatkoweInformacje</a>,<span class="stringliteral">"H2\""</span>);
<a name="l01853"></a>01853         <a class="code" href="main_8c.html#7ff0e94f5e3c9337353542d81db57104" title="Generuje pliki wynikowe dla odpowiednich algorytmow.">ZapiszWyniki</a>(nazwaPlikuH2bisOut);
<a name="l01854"></a>01854     }
<a name="l01855"></a>01855 }
<a name="l01856"></a>01856 
<a name="l01857"></a>01857 
<a name="l01858"></a>01858 <span class="comment">/* ======================================================================</span>
<a name="l01859"></a>01859 <span class="comment"> *  GLPK_R_D</span>
<a name="l01860"></a>01860 <span class="comment"> * ====================================================================== */</span>
<a name="l01925"></a><a class="code" href="main_8c.html#93e8ae2f06f58ce7bbc167f83da651f9">01925</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#93e8ae2f06f58ce7bbc167f83da651f9" title="Umozliwia rozwiazanie problemu przez zewnetrzny solver (GLPK).">GLPK_R_D</a>()
<a name="l01926"></a>01926 {
<a name="l01927"></a>01927     <span class="keywordtype">char</span> nazwaPlikuDanychGLPK[64];
<a name="l01928"></a>01928     strcpy(nazwaPlikuDanychGLPK,<a class="code" href="main_8c.html#e401adba12fa394291ec56e59e8120f4">nazwaPlikuWejsciowego</a>);
<a name="l01929"></a>01929     strcat(nazwaPlikuDanychGLPK,<span class="stringliteral">"_GLPK_dat"</span>);
<a name="l01930"></a>01930 
<a name="l01931"></a>01931     FILE *plikDanychGLPK;
<a name="l01932"></a>01932     <span class="keywordflow">if</span> (((plikDanychGLPK=fopen(nazwaPlikuDanychGLPK, <span class="stringliteral">"w"</span>))==NULL))
<a name="l01933"></a>01933     {
<a name="l01934"></a>01934         printf(<span class="stringliteral">"Nie mozna otworzyc pliku wyjsciowego do zapisu modelu GMPL.\n"</span>);
<a name="l01935"></a>01935         exit(1);
<a name="l01936"></a>01936     }
<a name="l01937"></a>01937     <span class="keywordflow">else</span>
<a name="l01938"></a>01938         <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>)
<a name="l01939"></a>01939             printf(<span class="stringliteral">"\n\nOtwarto plik do zapisu danych modelu GMPL.\n"</span>);
<a name="l01940"></a>01940 
<a name="l01941"></a>01941 
<a name="l01942"></a>01942     <span class="comment">/* ZAPIS DANYCH W FORMACIE GMPL */</span>
<a name="l01943"></a>01943     fprintf(plikDanychGLPK,<span class="stringliteral">"data;\n"</span>);
<a name="l01944"></a>01944     fprintf(plikDanychGLPK,<span class="stringliteral">"param N := %d ;\n"</span>,<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>);
<a name="l01945"></a>01945     fprintf(plikDanychGLPK,<span class="stringliteral">"param K := %d ;\n"</span>,<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>);
<a name="l01946"></a>01946     fprintf(plikDanychGLPK,<span class="stringliteral">"param c := %d ;\n\n"</span>,<a class="code" href="main_8c.html#4e1e0e72dd773439e333c84dd762a9c3" title="Maksymalna wielkosc alokacji zasobow.">c</a>);
<a name="l01947"></a>01947 
<a name="l01948"></a>01948     fprintf(plikDanychGLPK,<span class="stringliteral">"param p := \n"</span>);
<a name="l01949"></a>01949     <span class="keywordtype">int</span> i;
<a name="l01950"></a>01950     <span class="keywordflow">for</span> (i=1;i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>;i++)
<a name="l01951"></a>01951     {
<a name="l01952"></a>01952         fprintf(plikDanychGLPK,<span class="stringliteral">"\n%d\t%d"</span>,i,<a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[i]);
<a name="l01953"></a>01953     }
<a name="l01954"></a>01954     fprintf(plikDanychGLPK,<span class="stringliteral">";\n\n"</span>);
<a name="l01955"></a>01955 
<a name="l01956"></a>01956     fprintf(plikDanychGLPK,<span class="stringliteral">"param w := \n"</span>);
<a name="l01957"></a>01957     <span class="keywordflow">for</span> (i=1;i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>;i++)
<a name="l01958"></a>01958     {
<a name="l01959"></a>01959         fprintf(plikDanychGLPK,<span class="stringliteral">"\n%d\t%d"</span>,i,<a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[i]);
<a name="l01960"></a>01960     }
<a name="l01961"></a>01961     fprintf(plikDanychGLPK,<span class="stringliteral">";\nend;\n"</span>);
<a name="l01962"></a>01962     fclose(plikDanychGLPK);
<a name="l01963"></a>01963 
<a name="l01964"></a>01964     <span class="comment">/* UWORZENIE MODELU DANYCH - ZADANIE ZRELAKSOWANE */</span>
<a name="l01965"></a>01965     <span class="keywordtype">char</span> nazwaPlikuModeluGLPK_R[256];
<a name="l01966"></a>01966     tmpnam(nazwaPlikuModeluGLPK_R);
<a name="l01967"></a>01967     strcat(nazwaPlikuModeluGLPK_R,<span class="stringliteral">"_R.mod"</span>);
<a name="l01968"></a>01968 
<a name="l01969"></a>01969     FILE * KP01_R_model = fopen(nazwaPlikuModeluGLPK_R,<span class="stringliteral">"w"</span>);
<a name="l01970"></a>01970     <span class="keywordflow">if</span> (KP01_R_model==NULL)
<a name="l01971"></a>01971     {
<a name="l01972"></a>01972         printf(<span class="stringliteral">"Blad, nie mozna utworzyc tymczasowego pliku do zapisu modelu GLPK!\n"</span>);
<a name="l01973"></a>01973         <span class="keywordflow">return</span>;
<a name="l01974"></a>01974     }
<a name="l01975"></a>01975     fprintf(KP01_R_model,<span class="stringliteral">"%s"</span>,<a class="code" href="main_8h.html#689c7814b58c9ff6a60412016bb1ab9f">KP01_R</a>);
<a name="l01976"></a>01976     fclose(KP01_R_model);
<a name="l01977"></a>01977 
<a name="l01978"></a>01978     <span class="comment">/* Plik LP wygenerowano. Rozwiazujemy problem zrelaksowany.</span>
<a name="l01979"></a>01979 <span class="comment">     * Warunek - dostep do glpsol.exe w zmiennej srodowiskowej PATH.</span>
<a name="l01980"></a>01980 <span class="comment">     * W srodowisku UNIX/Linux analogicznie nalezy zmienic ponizsza komende z glpsol.exe na glpsol */</span>
<a name="l01981"></a>01981     <span class="keywordtype">char</span> wywolanieGLPSOL[128];
<a name="l01982"></a>01982     <span class="keywordtype">char</span> nazwaPlikuWyjsciowegoGLPK_R_out[256],nazwaPlikuWyjsciowegoGLPK_R_log[256];
<a name="l01983"></a>01983 
<a name="l01984"></a>01984     tmpnam(nazwaPlikuWyjsciowegoGLPK_R_out);
<a name="l01985"></a>01985     strcat(nazwaPlikuWyjsciowegoGLPK_R_out,<span class="stringliteral">"_R.out"</span>);
<a name="l01986"></a>01986 
<a name="l01987"></a>01987     tmpnam(nazwaPlikuWyjsciowegoGLPK_R_log);
<a name="l01988"></a>01988     strcat(nazwaPlikuWyjsciowegoGLPK_R_log,<span class="stringliteral">"_R.log"</span>);
<a name="l01989"></a>01989 
<a name="l01990"></a>01990     sprintf(wywolanieGLPSOL,<span class="stringliteral">"glpsol.exe -d %s -m %s -w %s --log %s &gt;&gt; aa.txt"</span>,nazwaPlikuDanychGLPK,nazwaPlikuModeluGLPK_R,nazwaPlikuWyjsciowegoGLPK_R_out,nazwaPlikuWyjsciowegoGLPK_R_log);
<a name="l01991"></a>01991     <span class="keywordtype">double</span> wynik = -1;
<a name="l01992"></a>01992     <a class="code" href="main_8c.html#e9284b236f128677657631ae56843cae" title="Jedna z funkcji do pomiaru czasu. ,,Uruchamia&amp;quot; zegar zapisujac w zmiennej czasStartowy...">CzasStart</a>();
<a name="l01993"></a>01993     system(wywolanieGLPSOL);
<a name="l01994"></a>01994     <a class="code" href="main_8c.html#2cc2c7e7811c4a88e4dc3ee60b801508" title="Jedna z funkcji do pomiaru czasu. ,,Uruchamia&amp;quot; zegar zapisujac w zmiennej czasStartowy...">CzasStop</a>();
<a name="l01995"></a>01995 
<a name="l01996"></a>01996     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>!=1)
<a name="l01997"></a>01997         <span class="keyword">remove</span>(nazwaPlikuModeluGLPK_R);
<a name="l01998"></a>01998 
<a name="l01999"></a>01999     <span class="comment">/* Parse'owanie pliku wyjsciowego zadania zrelaksowanego */</span>
<a name="l02000"></a>02000     <span class="keywordtype">char</span> tmp[128];
<a name="l02001"></a>02001     FILE * GLPK_R_Out = fopen(nazwaPlikuWyjsciowegoGLPK_R_out,<span class="stringliteral">"a+"</span>);
<a name="l02002"></a>02002     fgets(tmp,128,GLPK_R_Out);
<a name="l02003"></a>02003     fgets(tmp,128,GLPK_R_Out);
<a name="l02004"></a>02004     fclose(GLPK_R_Out);
<a name="l02005"></a>02005 
<a name="l02006"></a>02006     <span class="keywordtype">int</span> itmp1,itmp2;
<a name="l02007"></a>02007     sscanf(tmp,<span class="stringliteral">"%d %d %lf\n"</span>,&amp;itmp1,&amp;itmp2,&amp;wynik);
<a name="l02008"></a>02008 
<a name="l02009"></a>02009     <a class="code" href="main_8c.html#bc046b760068e2015d1f943257ad1c9d">wynikAlokacja</a>[<a class="code" href="main_8c.html#99a3a311f73faef2c0af730e7f4dd00b">GLPK_R</a>] = wynik;
<a name="l02010"></a>02010     <a class="code" href="main_8c.html#b0c1a864c503ead10e2426d29c03fcc5">wynikCzas</a>[<a class="code" href="main_8c.html#99a3a311f73faef2c0af730e7f4dd00b">GLPK_R</a>] = <a class="code" href="main_8c.html#6ced5c44871ebf39b65910b5726a3de0">czasAlgorytmu</a>;
<a name="l02011"></a>02011 
<a name="l02012"></a>02012     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>!=1)
<a name="l02013"></a>02013         <span class="keyword">remove</span>(nazwaPlikuWyjsciowegoGLPK_R_out);
<a name="l02014"></a>02014 
<a name="l02015"></a>02015     <span class="comment">/* Parse'owanie loga zadania zrelaksowanego */</span>
<a name="l02016"></a>02016     <span class="comment">/*</span>
<a name="l02017"></a>02017 <span class="comment">     * @todo</span>
<a name="l02018"></a>02018 <span class="comment">     */</span>
<a name="l02019"></a>02019     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a>!=1)
<a name="l02020"></a>02020         <span class="keyword">remove</span>(nazwaPlikuWyjsciowegoGLPK_R_log);
<a name="l02021"></a>02021 
<a name="l02022"></a>02022     <span class="comment">/* ROZWIAZANIE DOKLADNE */</span>
<a name="l02023"></a>02023     wynik = -1;
<a name="l02024"></a>02024 
<a name="l02025"></a>02025     <span class="comment">/* Stworzenie modelu zadania GLPK - dokladnego */</span>
<a name="l02026"></a>02026     <span class="keywordtype">char</span> nazwaPlikuModeluGLPK_D[256];
<a name="l02027"></a>02027     tmpnam(nazwaPlikuModeluGLPK_D);
<a name="l02028"></a>02028     strcat(nazwaPlikuModeluGLPK_D,<span class="stringliteral">"_D.mod"</span>);
<a name="l02029"></a>02029 
<a name="l02030"></a>02030     FILE * KP01_D_model = fopen(nazwaPlikuModeluGLPK_D,<span class="stringliteral">"w"</span>);
<a name="l02031"></a>02031     <span class="keywordflow">if</span> (KP01_R_model==NULL)
<a name="l02032"></a>02032     {
<a name="l02033"></a>02033         printf(<span class="stringliteral">"Blad, nie mozna utworzyc tymczasowego pliku do zapisu modelu GLPK!\n"</span>);
<a name="l02034"></a>02034         <span class="keywordflow">return</span>;
<a name="l02035"></a>02035     }
<a name="l02036"></a>02036     fprintf(KP01_D_model,<span class="stringliteral">"%s"</span>,<a class="code" href="main_8h.html#647b0fdf81ddfa7573e0f8fcd0708e13">KP01_D</a>);
<a name="l02037"></a>02037     fclose(KP01_D_model);
<a name="l02038"></a>02038 
<a name="l02039"></a>02039     <span class="keywordtype">char</span> nazwaPlikuWyjsciowegoGLPK_D_out[256], nazwaPlikuWyjsciowegoGLPK_D_log[256];
<a name="l02040"></a>02040 
<a name="l02041"></a>02041     strcpy(nazwaPlikuWyjsciowegoGLPK_D_out,<a class="code" href="main_8c.html#e13ce79999caa4f4e3e787ee9a17ec0e">nazwaProblemu</a>);
<a name="l02042"></a>02042     strcat(nazwaPlikuWyjsciowegoGLPK_D_out,<span class="stringliteral">"_LP_D_out.txt"</span>);
<a name="l02043"></a>02043 
<a name="l02044"></a>02044     tmpnam(nazwaPlikuWyjsciowegoGLPK_D_log);
<a name="l02045"></a>02045     strcat(nazwaPlikuWyjsciowegoGLPK_D_log,<span class="stringliteral">"_D.log"</span>);
<a name="l02046"></a>02046 
<a name="l02047"></a>02047     sprintf(wywolanieGLPSOL,<span class="stringliteral">"glpsol.exe -d %s -m %s -w %s --log %s"</span>,nazwaPlikuDanychGLPK,nazwaPlikuModeluGLPK_D,nazwaPlikuWyjsciowegoGLPK_D_out,nazwaPlikuWyjsciowegoGLPK_D_log);
<a name="l02048"></a>02048 
<a name="l02049"></a>02049     <a class="code" href="main_8c.html#e9284b236f128677657631ae56843cae" title="Jedna z funkcji do pomiaru czasu. ,,Uruchamia&amp;quot; zegar zapisujac w zmiennej czasStartowy...">CzasStart</a>();
<a name="l02050"></a>02050     system(wywolanieGLPSOL);
<a name="l02051"></a>02051     <a class="code" href="main_8c.html#2cc2c7e7811c4a88e4dc3ee60b801508" title="Jedna z funkcji do pomiaru czasu. ,,Uruchamia&amp;quot; zegar zapisujac w zmiennej czasStartowy...">CzasStop</a>();
<a name="l02052"></a>02052 
<a name="l02053"></a>02053     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a> != 1)
<a name="l02054"></a>02054         <span class="keyword">remove</span>(nazwaPlikuModeluGLPK_D);
<a name="l02055"></a>02055 
<a name="l02056"></a>02056     <span class="comment">/* Parse'owanie pliku wyjsciowego algorytmu dokladnego */</span>
<a name="l02057"></a>02057     FILE * GLPK_D_Out = fopen(nazwaPlikuWyjsciowegoGLPK_D_out,<span class="stringliteral">"a+"</span>);
<a name="l02058"></a>02058     fgets(tmp,128,GLPK_D_Out);
<a name="l02059"></a>02059     fgets(tmp,128,GLPK_D_Out);
<a name="l02060"></a>02060     fclose(GLPK_D_Out);
<a name="l02061"></a>02061 
<a name="l02062"></a>02062     sscanf(tmp,<span class="stringliteral">"%d %lf\n"</span>,&amp;itmp1,&amp;wynik);
<a name="l02063"></a>02063 
<a name="l02064"></a>02064     <a class="code" href="main_8c.html#bc046b760068e2015d1f943257ad1c9d">wynikAlokacja</a>[<a class="code" href="main_8c.html#0ac59573db46e3d633836e727f08aa0e">GLPK_D</a>] = wynik;
<a name="l02065"></a>02065     <a class="code" href="main_8c.html#b0c1a864c503ead10e2426d29c03fcc5">wynikCzas</a>[<a class="code" href="main_8c.html#0ac59573db46e3d633836e727f08aa0e">GLPK_D</a>] = <a class="code" href="main_8c.html#6ced5c44871ebf39b65910b5726a3de0">czasAlgorytmu</a>;
<a name="l02066"></a>02066 
<a name="l02067"></a>02067     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a> != 1)
<a name="l02068"></a>02068         <span class="keyword">remove</span>(nazwaPlikuWyjsciowegoGLPK_D_out);
<a name="l02069"></a>02069 
<a name="l02070"></a>02070     <span class="comment">/*</span>
<a name="l02071"></a>02071 <span class="comment">     * parse'owanie loga</span>
<a name="l02072"></a>02072 <span class="comment">     *</span>
<a name="l02073"></a>02073 <span class="comment">     *</span>
<a name="l02074"></a>02074 <span class="comment">     *</span>
<a name="l02075"></a>02075 <span class="comment">     */</span>
<a name="l02076"></a>02076     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a> != 1)
<a name="l02077"></a>02077         <span class="keyword">remove</span>(nazwaPlikuWyjsciowegoGLPK_D_log);
<a name="l02078"></a>02078 
<a name="l02079"></a>02079     <span class="comment">/* Posprzatanie */</span>
<a name="l02080"></a>02080     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a> != 1)
<a name="l02081"></a>02081         <span class="keyword">remove</span>(nazwaPlikuDanychGLPK);
<a name="l02082"></a>02082 }
<a name="l02083"></a>02083 
<a name="l02084"></a>02084 <span class="comment">/* ======================================================================</span>
<a name="l02085"></a>02085 <span class="comment"> *  Rozwiaz</span>
<a name="l02086"></a>02086 <span class="comment"> *</span>
<a name="l02087"></a>02087 <span class="comment"> *  @brief Rozwiazuje problem wybranym algorytmem.</span>
<a name="l02088"></a>02088 <span class="comment"> *</span>
<a name="l02089"></a>02089 <span class="comment"> *  @param nazwaAlgorytmu jedna z predefiniowanych wartosci stalej {REL, H1, H2, H2P, H2B}</span>
<a name="l02090"></a>02090 <span class="comment"> * ====================================================================== */</span>
<a name="l02091"></a><a class="code" href="main_8c.html#b992ab2c9b3d0c6a6b293f8d110d8cbc">02091</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#b992ab2c9b3d0c6a6b293f8d110d8cbc">Rozwiaz</a>(<span class="keywordtype">int</span> nazwaAlgorytmu)
<a name="l02092"></a>02092 {
<a name="l02093"></a>02093     <span class="keywordflow">switch</span>(nazwaAlgorytmu)
<a name="l02094"></a>02094     {
<a name="l02095"></a>02095     <span class="keywordflow">case</span> <a class="code" href="main_8c.html#e41c8500c68b74939c9beab3ff16990e">REL</a>:
<a name="l02096"></a>02096         <a class="code" href="main_8c.html#86892a380cb93ebd030dba5a6302be06" title="Inicjalizuje czesc wektorow.">InicjujDane</a>();
<a name="l02097"></a>02097         <a class="code" href="main_8c.html#e9284b236f128677657631ae56843cae" title="Jedna z funkcji do pomiaru czasu. ,,Uruchamia&amp;quot; zegar zapisujac w zmiennej czasStartowy...">CzasStart</a>();
<a name="l02098"></a>02098         <a class="code" href="main_8c.html#cdd4e11b1fc38e16d036b25d02df00f0" title="Implementacja rozwiazania zrelaksowanego problemu KP01&amp;lt;=K.">Relaksacja</a>();
<a name="l02099"></a>02099         <a class="code" href="main_8c.html#2cc2c7e7811c4a88e4dc3ee60b801508" title="Jedna z funkcji do pomiaru czasu. ,,Uruchamia&amp;quot; zegar zapisujac w zmiennej czasStartowy...">CzasStop</a>();
<a name="l02100"></a>02100         <a class="code" href="main_8c.html#b0c1a864c503ead10e2426d29c03fcc5">wynikCzas</a>[<a class="code" href="main_8c.html#e41c8500c68b74939c9beab3ff16990e">REL</a>] = <a class="code" href="main_8c.html#6ced5c44871ebf39b65910b5726a3de0">czasAlgorytmu</a>;
<a name="l02101"></a>02101         <span class="keywordflow">break</span>;
<a name="l02102"></a>02102     <span class="keywordflow">case</span> <a class="code" href="main_8c.html#3e4baeb2553d751ae0c007569655a137">H1</a>:
<a name="l02103"></a>02103         <a class="code" href="main_8c.html#86892a380cb93ebd030dba5a6302be06" title="Inicjalizuje czesc wektorow.">InicjujDane</a>();
<a name="l02104"></a>02104         <a class="code" href="main_8c.html#e9284b236f128677657631ae56843cae" title="Jedna z funkcji do pomiaru czasu. ,,Uruchamia&amp;quot; zegar zapisujac w zmiennej czasStartowy...">CzasStart</a>();
<a name="l02105"></a>02105         <a class="code" href="main_8c.html#e85b4a7b11917a85362470a56128e990" title="Implementacja algorytmu H1 problemu KP01&amp;lt;=K.">AlgorytmH1</a>();
<a name="l02106"></a>02106         <a class="code" href="main_8c.html#2cc2c7e7811c4a88e4dc3ee60b801508" title="Jedna z funkcji do pomiaru czasu. ,,Uruchamia&amp;quot; zegar zapisujac w zmiennej czasStartowy...">CzasStop</a>();
<a name="l02107"></a>02107         <a class="code" href="main_8c.html#b0c1a864c503ead10e2426d29c03fcc5">wynikCzas</a>[<a class="code" href="main_8c.html#3e4baeb2553d751ae0c007569655a137">H1</a>] = <a class="code" href="main_8c.html#6ced5c44871ebf39b65910b5726a3de0">czasAlgorytmu</a>;
<a name="l02108"></a>02108         <span class="keywordflow">break</span>;
<a name="l02109"></a>02109     <span class="keywordflow">case</span> <a class="code" href="main_8c.html#b5e8a97982062958fb8f58a428df09ee">H2</a>:
<a name="l02110"></a>02110         <a class="code" href="main_8c.html#86892a380cb93ebd030dba5a6302be06" title="Inicjalizuje czesc wektorow.">InicjujDane</a>();
<a name="l02111"></a>02111         <a class="code" href="main_8c.html#e9284b236f128677657631ae56843cae" title="Jedna z funkcji do pomiaru czasu. ,,Uruchamia&amp;quot; zegar zapisujac w zmiennej czasStartowy...">CzasStart</a>();
<a name="l02112"></a>02112         <a class="code" href="main_8c.html#7afb6457bc15f6a1fea27f461601e850" title="Implementacja algorytmu H2 problemu KP01&amp;lt;=K.">AlgorytmH2</a>();
<a name="l02113"></a>02113         <a class="code" href="main_8c.html#2cc2c7e7811c4a88e4dc3ee60b801508" title="Jedna z funkcji do pomiaru czasu. ,,Uruchamia&amp;quot; zegar zapisujac w zmiennej czasStartowy...">CzasStop</a>();
<a name="l02114"></a>02114         <a class="code" href="main_8c.html#b0c1a864c503ead10e2426d29c03fcc5">wynikCzas</a>[<a class="code" href="main_8c.html#b5e8a97982062958fb8f58a428df09ee">H2</a>] = <a class="code" href="main_8c.html#6ced5c44871ebf39b65910b5726a3de0">czasAlgorytmu</a>;
<a name="l02115"></a>02115         <span class="keywordflow">break</span>;
<a name="l02116"></a>02116     <span class="keywordflow">case</span> <a class="code" href="main_8c.html#e3ea6c504e916b75b4e44abeffdb8477">H2P</a>:
<a name="l02117"></a>02117         <a class="code" href="main_8c.html#86892a380cb93ebd030dba5a6302be06" title="Inicjalizuje czesc wektorow.">InicjujDane</a>();
<a name="l02118"></a>02118         <a class="code" href="main_8c.html#e9284b236f128677657631ae56843cae" title="Jedna z funkcji do pomiaru czasu. ,,Uruchamia&amp;quot; zegar zapisujac w zmiennej czasStartowy...">CzasStart</a>();
<a name="l02119"></a>02119         <a class="code" href="main_8c.html#c7f7228e325a7bc232d8940ccec07979" title="Implementacja algorytmu H2&amp;#39; problemu KP01&amp;lt;=K.">AlgorytmH2Prim</a>();
<a name="l02120"></a>02120         <a class="code" href="main_8c.html#2cc2c7e7811c4a88e4dc3ee60b801508" title="Jedna z funkcji do pomiaru czasu. ,,Uruchamia&amp;quot; zegar zapisujac w zmiennej czasStartowy...">CzasStop</a>();
<a name="l02121"></a>02121         <a class="code" href="main_8c.html#b0c1a864c503ead10e2426d29c03fcc5">wynikCzas</a>[<a class="code" href="main_8c.html#e3ea6c504e916b75b4e44abeffdb8477">H2P</a>] = <a class="code" href="main_8c.html#6ced5c44871ebf39b65910b5726a3de0">czasAlgorytmu</a>;
<a name="l02122"></a>02122         <span class="keywordflow">break</span>;
<a name="l02123"></a>02123     <span class="keywordflow">case</span> <a class="code" href="main_8c.html#13ba4f47dcd4f3e4a0dca6330c1916f2">H2B</a>:
<a name="l02124"></a>02124         <a class="code" href="main_8c.html#86892a380cb93ebd030dba5a6302be06" title="Inicjalizuje czesc wektorow.">InicjujDane</a>();
<a name="l02125"></a>02125         <a class="code" href="main_8c.html#e9284b236f128677657631ae56843cae" title="Jedna z funkcji do pomiaru czasu. ,,Uruchamia&amp;quot; zegar zapisujac w zmiennej czasStartowy...">CzasStart</a>();
<a name="l02126"></a>02126         <a class="code" href="main_8c.html#779e9c536e6db05731f94e52eabadfdd" title="Implementacja algorytmu H2 BIS problemu KP01&amp;lt;=K.">AlgorytmH2Bis</a>();
<a name="l02127"></a>02127         <a class="code" href="main_8c.html#2cc2c7e7811c4a88e4dc3ee60b801508" title="Jedna z funkcji do pomiaru czasu. ,,Uruchamia&amp;quot; zegar zapisujac w zmiennej czasStartowy...">CzasStop</a>();
<a name="l02128"></a>02128         <a class="code" href="main_8c.html#b0c1a864c503ead10e2426d29c03fcc5">wynikCzas</a>[<a class="code" href="main_8c.html#13ba4f47dcd4f3e4a0dca6330c1916f2">H2B</a>] = <a class="code" href="main_8c.html#6ced5c44871ebf39b65910b5726a3de0">czasAlgorytmu</a>;
<a name="l02129"></a>02129         <span class="keywordflow">break</span>;
<a name="l02130"></a>02130     }
<a name="l02131"></a>02131 
<a name="l02132"></a>02132 }
<a name="l02133"></a>02133 
<a name="l02134"></a>02134 
<a name="l02135"></a><a class="code" href="main_8c.html#7e6c8aa28f18251d5f3b470a18864e27">02135</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#7e6c8aa28f18251d5f3b470a18864e27">RozwiazWszystkie</a>()
<a name="l02136"></a>02136 {
<a name="l02137"></a>02137     <a class="code" href="main_8c.html#b992ab2c9b3d0c6a6b293f8d110d8cbc">Rozwiaz</a>(<a class="code" href="main_8c.html#e41c8500c68b74939c9beab3ff16990e">REL</a>);
<a name="l02138"></a>02138     <a class="code" href="main_8c.html#b992ab2c9b3d0c6a6b293f8d110d8cbc">Rozwiaz</a>(<a class="code" href="main_8c.html#3e4baeb2553d751ae0c007569655a137">H1</a>);
<a name="l02139"></a>02139     <a class="code" href="main_8c.html#b992ab2c9b3d0c6a6b293f8d110d8cbc">Rozwiaz</a>(<a class="code" href="main_8c.html#b5e8a97982062958fb8f58a428df09ee">H2</a>);
<a name="l02140"></a>02140     <a class="code" href="main_8c.html#b992ab2c9b3d0c6a6b293f8d110d8cbc">Rozwiaz</a>(<a class="code" href="main_8c.html#e3ea6c504e916b75b4e44abeffdb8477">H2P</a>);
<a name="l02141"></a>02141     <a class="code" href="main_8c.html#b992ab2c9b3d0c6a6b293f8d110d8cbc">Rozwiaz</a>(<a class="code" href="main_8c.html#13ba4f47dcd4f3e4a0dca6330c1916f2">H2B</a>);
<a name="l02142"></a>02142     <a class="code" href="main_8c.html#93e8ae2f06f58ce7bbc167f83da651f9" title="Umozliwia rozwiazanie problemu przez zewnetrzny solver (GLPK).">GLPK_R_D</a>();
<a name="l02143"></a>02143 }
<a name="l02144"></a>02144 
<a name="l02145"></a>02145 <span class="comment">/* ======================================================================</span>
<a name="l02146"></a>02146 <span class="comment"> *  Tworz Zbior Testowy</span>
<a name="l02147"></a>02147 <span class="comment"> * ====================================================================== */</span>
<a name="l02159"></a><a class="code" href="main_8c.html#7cdee1c33e71451a88cb70a774028886">02159</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#7cdee1c33e71451a88cb70a774028886" title="Tworzy jeden zbior danych (N par [p,w]), funkcja jest sterowana struktura params...">TworzZbiorTestowy</a>(<span class="keywordtype">int</span> intN, <span class="keywordtype">int</span> wfunc, <span class="keywordtype">int</span> pfunc, <span class="keywordtype">int</span> *w_params, <span class="keywordtype">int</span> *p_params)
<a name="l02160"></a>02160 {
<a name="l02161"></a>02161 
<a name="l02162"></a>02162     <a class="code" href="main_8c.html#01f7419ee78625ea24a0522dbd13917c">ZwolnijPamiec</a>();
<a name="l02163"></a>02163     <a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a> = intN;
<a name="l02164"></a>02164     <a class="code" href="main_8c.html#bbeebdb30d90a79d95cab377a59f62f0" title="Dynamiczny alokator danych.">AlokujPamiec</a>(intN);
<a name="l02165"></a>02165     <span class="keywordtype">int</span> i;
<a name="l02166"></a>02166 
<a name="l02167"></a>02167     <span class="keywordtype">int</span> suma_w = 0;
<a name="l02168"></a>02168 
<a name="l02169"></a>02169 
<a name="l02170"></a>02170     <span class="keywordflow">switch</span> (wfunc)
<a name="l02171"></a>02171     {
<a name="l02172"></a>02172         <span class="comment">// w_i = w_params[0] na sztywno</span>
<a name="l02173"></a>02173     <span class="keywordflow">case</span> 0:
<a name="l02174"></a>02174         <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l02175"></a>02175             <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[i] = w_params[0];
<a name="l02176"></a>02176 
<a name="l02177"></a>02177         <span class="comment">// w zbiorze &lt;w_0 - delta_w, w_0 + delta_w&gt;</span>
<a name="l02178"></a>02178         <span class="comment">// w_0 = params[0]</span>
<a name="l02179"></a>02179         <span class="comment">// delta_w = params[1]</span>
<a name="l02180"></a>02180         <span class="keywordflow">break</span>;
<a name="l02181"></a>02181     <span class="keywordflow">case</span> 1:
<a name="l02182"></a>02182             <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l02183"></a>02183                 <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[i] = w_params[0]-w_params[1]+2*(rand()%w_params[1]);
<a name="l02184"></a>02184         <span class="keywordflow">break</span>;
<a name="l02185"></a>02185 
<a name="l02186"></a>02186         <span class="comment">// domyslnie - random (1,100)</span>
<a name="l02187"></a>02187     <span class="keywordflow">default</span>:
<a name="l02188"></a>02188             <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l02189"></a>02189                 <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[i] = 1 + rand()%100;
<a name="l02190"></a>02190         <span class="keywordflow">break</span>;
<a name="l02191"></a>02191     }
<a name="l02192"></a>02192 
<a name="l02193"></a>02193     <span class="keywordflow">switch</span> (pfunc)
<a name="l02194"></a>02194     {
<a name="l02195"></a>02195         <span class="comment">// p = w</span>
<a name="l02196"></a>02196     <span class="keywordflow">case</span> 1:
<a name="l02197"></a>02197         <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l02198"></a>02198             <a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[i] = <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[i];
<a name="l02199"></a>02199         <span class="keywordflow">break</span>;
<a name="l02200"></a>02200 
<a name="l02201"></a>02201         <span class="comment">// p = w + delta_p</span>
<a name="l02202"></a>02202         <span class="comment">// delta_p = p_params[0]</span>
<a name="l02203"></a>02203     <span class="keywordflow">case</span> 2:
<a name="l02204"></a>02204             <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l02205"></a>02205                 <a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[i] = <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[i] + p_params[0];
<a name="l02206"></a>02206         <span class="keywordflow">break</span>;
<a name="l02207"></a>02207 
<a name="l02208"></a>02208         <span class="comment">// p = &lt;w - delta_p, w + delta_p&gt;</span>
<a name="l02209"></a>02209         <span class="comment">// delta_p = p_params[0]</span>
<a name="l02210"></a>02210     <span class="keywordflow">case</span> 3:
<a name="l02211"></a>02211             <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l02212"></a>02212                 <a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[i] = <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[i] - p_params[0] + 2*(rand()%p_params[0]);
<a name="l02213"></a>02213         <span class="keywordflow">break</span>;
<a name="l02214"></a>02214 
<a name="l02215"></a>02215     <span class="keywordflow">default</span>:
<a name="l02216"></a>02216             <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l02217"></a>02217                 <a class="code" href="main_8c.html#61b0821c8ee2a2df1d8cf38ebe0f2b3c" title="Wektor profitow.">p</a>[i] = 1 + rand()%100;
<a name="l02218"></a>02218         <span class="keywordflow">break</span>;
<a name="l02219"></a>02219     }
<a name="l02220"></a>02220 
<a name="l02221"></a>02221     <span class="keywordflow">for</span> (i=1; i&lt;=<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>; i++)
<a name="l02222"></a>02222         suma_w += <a class="code" href="main_8c.html#95b0e3277cc37e1b347b4521b9942d42" title="Wektor zapotrzebowan na zasob.">w</a>[i];
<a name="l02223"></a>02223 
<a name="l02224"></a>02224     <a class="code" href="main_8c.html#4e1e0e72dd773439e333c84dd762a9c3" title="Maksymalna wielkosc alokacji zasobow.">c</a> = suma_w/2;
<a name="l02225"></a>02225     <span class="comment">//K = 2*N/3;</span>
<a name="l02226"></a>02226 
<a name="l02227"></a>02227     <a class="code" href="main_8c.html#86892a380cb93ebd030dba5a6302be06" title="Inicjalizuje czesc wektorow.">InicjujDane</a>();
<a name="l02228"></a>02228 
<a name="l02229"></a>02229 }
<a name="l02230"></a>02230 
<a name="l02231"></a>02231 
<a name="l02232"></a><a class="code" href="main_8c.html#d9805ba6af3fe680d7179e3983e5abbd">02232</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#d9805ba6af3fe680d7179e3983e5abbd">PrzeprowadzTest</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>* nazwaTestu, <span class="keywordtype">int</span> instancje, <span class="keywordtype">int</span> intN, <span class="keywordtype">int</span> wfunc, <span class="keywordtype">int</span> pfunc, <span class="keywordtype">int</span> *w_params, <span class="keywordtype">int</span> *p_params)
<a name="l02233"></a>02233 {
<a name="l02234"></a>02234         srand(time(NULL));
<a name="l02235"></a>02235 
<a name="l02236"></a>02236         <span class="keywordtype">char</span> * nazwaPliku[256];
<a name="l02237"></a>02237         strcpy(nazwaPliku,nazwaTestu);
<a name="l02238"></a>02238         strcat(nazwaPliku,<span class="stringliteral">".tsv"</span>);
<a name="l02239"></a>02239 
<a name="l02240"></a>02240         FILE * test1 = fopen(nazwaPliku,<span class="stringliteral">"w"</span>);
<a name="l02241"></a>02241         <span class="keywordtype">int</span> i;
<a name="l02242"></a>02242     <span class="keywordflow">for</span> (i=0; i&lt;7; i++)
<a name="l02243"></a>02243         fprintf(test1,<span class="stringliteral">"%s\t\t"</span>,<a class="code" href="main_8c.html#29b4c5424b00e8c417f6cd28b91c6246">nazwy</a>[i]);
<a name="l02244"></a>02244     fprintf(test1,<span class="stringliteral">"\n"</span>);
<a name="l02245"></a>02245     <span class="keywordflow">for</span> (i=0; i&lt;7; i++)
<a name="l02246"></a>02246         fprintf(test1,<span class="stringliteral">"z\tt\t"</span>);
<a name="l02247"></a>02247     fprintf(test1,<span class="stringliteral">"\n"</span>);
<a name="l02248"></a>02248 
<a name="l02249"></a>02249 
<a name="l02250"></a>02250     <span class="keywordflow">for</span> (i=1; i&lt;=instancje;i++)
<a name="l02251"></a>02251     {
<a name="l02252"></a>02252         <a class="code" href="main_8c.html#7cdee1c33e71451a88cb70a774028886" title="Tworzy jeden zbior danych (N par [p,w]), funkcja jest sterowana struktura params...">TworzZbiorTestowy</a>(intN,wfunc,pfunc,w_params,p_params);
<a name="l02253"></a>02253         printf(<span class="stringliteral">"INSTANCJA %d. N = %d, c = %d, K = %d\n"</span>,i,<a class="code" href="main_8c.html#7722c8ecbb62d99aee7ce68b1752f337" title="Liczba wszystkich mozliwych podmiotow.">N</a>,<a class="code" href="main_8c.html#4e1e0e72dd773439e333c84dd762a9c3" title="Maksymalna wielkosc alokacji zasobow.">c</a>,<a class="code" href="main_8c.html#2689c4b3931025b79053532a5f1b0a85" title="Liczba okreslajaca maksymalna liczbe podmiotow, ktorym mozna przydzielic zasob.">K</a>);
<a name="l02254"></a>02254 
<a name="l02255"></a>02255         <a class="code" href="main_8c.html#7e6c8aa28f18251d5f3b470a18864e27">RozwiazWszystkie</a>();
<a name="l02256"></a>02256         <span class="keywordtype">int</span> j;
<a name="l02257"></a>02257         <span class="keywordflow">for</span> (j=0; j&lt;7; j++)
<a name="l02258"></a>02258             fprintf(test1,<span class="stringliteral">"%.4f\t%d\t"</span>,<a class="code" href="main_8c.html#bc046b760068e2015d1f943257ad1c9d">wynikAlokacja</a>[j],<a class="code" href="main_8c.html#b0c1a864c503ead10e2426d29c03fcc5">wynikCzas</a>[j]);
<a name="l02259"></a>02259         fprintf(test1,<span class="stringliteral">"\n"</span>);
<a name="l02260"></a>02260     }
<a name="l02261"></a>02261     fclose(test1);
<a name="l02262"></a>02262 
<a name="l02263"></a>02263 
<a name="l02264"></a>02264 }
<a name="l02265"></a>02265 
<a name="l02266"></a>02266 
<a name="l02267"></a>02267 <span class="comment">/* ======================================================================</span>
<a name="l02268"></a>02268 <span class="comment"> *  MAIN</span>
<a name="l02269"></a>02269 <span class="comment"> * ====================================================================== */</span>
<a name="l02270"></a><a class="code" href="main_8c.html#0ddf1224851353fc92bfbff6f499fa97">02270</a> <span class="keywordtype">int</span> <a class="code" href="main_8c.html#0ddf1224851353fc92bfbff6f499fa97">main</a>(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[])
<a name="l02271"></a>02271 {
<a name="l02272"></a>02272 
<a name="l02273"></a>02273     <a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a> = 0;
<a name="l02274"></a>02274 
<a name="l02275"></a>02275 
<a name="l02276"></a>02276     <span class="keywordflow">if</span> (argc==1)
<a name="l02277"></a>02277         <a class="code" href="main_8c.html#32d9cda086dbd06f8c1fe3f430611d9a" title="Wczytuje dane z pliku.">WczytajDaneWejsciowe</a>(<span class="stringliteral">"dane/dane_qsort_check.txt"</span>);
<a name="l02278"></a>02278     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (argc==2)
<a name="l02279"></a>02279         <a class="code" href="main_8c.html#32d9cda086dbd06f8c1fe3f430611d9a" title="Wczytuje dane z pliku.">WczytajDaneWejsciowe</a>(argv[1]);
<a name="l02280"></a>02280     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (argc==3)
<a name="l02281"></a>02281     {
<a name="l02282"></a>02282         <a class="code" href="main_8c.html#1cd998b0d7070c500bf5f3423c428d4a" title="Okresla, czy program pracuje w &amp;#39;trybie glosnym&amp;#39;.">TRYB_DEBUG</a> = atoi(argv[2]);
<a name="l02283"></a>02283         <a class="code" href="main_8c.html#32d9cda086dbd06f8c1fe3f430611d9a" title="Wczytuje dane z pliku.">WczytajDaneWejsciowe</a>(argv[1]);
<a name="l02284"></a>02284     }
<a name="l02285"></a>02285 
<a name="l02286"></a>02286 
<a name="l02287"></a>02287 
<a name="l02288"></a>02288 <span class="comment">//    WypiszWektory(MSK_ALL,SORT_K);</span>
<a name="l02289"></a>02289 
<a name="l02290"></a>02290     <span class="keywordtype">char</span> nazwaPliku[128];
<a name="l02291"></a>02291     strcpy(nazwaPliku,<a class="code" href="main_8c.html#e13ce79999caa4f4e3e787ee9a17ec0e">nazwaProblemu</a>);
<a name="l02292"></a>02292     strcat(nazwaPliku,<span class="stringliteral">"_out.txt"</span>);
<a name="l02293"></a>02293 
<a name="l02294"></a>02294 
<a name="l02295"></a>02295 
<a name="l02296"></a>02296 
<a name="l02297"></a>02297     <a class="code" href="main_8c.html#7e6c8aa28f18251d5f3b470a18864e27">RozwiazWszystkie</a>();
<a name="l02298"></a>02298     <a class="code" href="main_8c.html#8bd72ae940fe946b5943662c5c41fd7a" title="Generuje plik z rozwiazaniem zbiorczym dla wielu algorytmow.">WynikiZbiorcze</a>(nazwaPliku);
<a name="l02299"></a>02299 
<a name="l02300"></a>02300 
<a name="l02301"></a>02301 
<a name="l02302"></a>02302 <span class="comment">//    int p_par[2];</span>
<a name="l02303"></a>02303 <span class="comment">//    int w_par[2];</span>
<a name="l02304"></a>02304 <span class="comment">//</span>
<a name="l02305"></a>02305 <span class="comment">//    // nazwa, ile_instancji, liczba elementow, w func, p func, w_par, p_par</span>
<a name="l02306"></a>02306 <span class="comment">//    w_par[0] = 20;</span>
<a name="l02307"></a>02307 <span class="comment">//    w_par[1] = 8;</span>
<a name="l02308"></a>02308 <span class="comment">//</span>
<a name="l02309"></a>02309 <span class="comment">//    p_par[0] = 4;</span>
<a name="l02310"></a>02310 <span class="comment">//    p_par[1] = 50;</span>
<a name="l02311"></a>02311 <span class="comment">//</span>
<a name="l02312"></a>02312 <span class="comment">//    //PrzeprowadzTest("TRZECI",5,100,1,3,w_par,p_par);</span>
<a name="l02313"></a>02313 <span class="comment">//</span>
<a name="l02314"></a>02314 <span class="comment">//    //WynikiZbiorcze("aa.txt");</span>
<a name="l02315"></a>02315 <span class="comment">//</span>
<a name="l02316"></a>02316 <span class="comment">//    TworzZbiorTestowy(10,1,3,w_par,p_par);</span>
<a name="l02317"></a>02317 <span class="comment">//    AlokujZachlannie();</span>
<a name="l02318"></a>02318    <span class="comment">// WypiszWektory(MSK_ALL, SORT_K);</span>
<a name="l02319"></a>02319 <span class="comment">//</span>
<a name="l02320"></a>02320 <span class="comment">//</span>
<a name="l02321"></a>02321 <span class="comment">//    i = 1;</span>
<a name="l02322"></a>02322 <span class="comment">//    for (i=1; i&lt;10; i++){</span>
<a name="l02323"></a>02323 <span class="comment">//      double Cakt = C(i);</span>
<a name="l02324"></a>02324 <span class="comment">//      printf("C(%d) = %f\n",i,Cakt);</span>
<a name="l02325"></a>02325 <span class="comment">//    }</span>
<a name="l02326"></a>02326 <span class="comment">//</span>
<a name="l02327"></a>02327 <span class="comment">//    lambda = 9999;</span>
<a name="l02328"></a>02328 <span class="comment">//    AktualizujZredukowaneWagi();</span>
<a name="l02329"></a>02329 <span class="comment">//    Sortuj();</span>
<a name="l02330"></a>02330 <span class="comment">//    C(99999);</span>
<a name="l02331"></a>02331 <span class="comment">//</span>
<a name="l02332"></a>02332 <span class="comment">//    printf("aktualne_C = %d\n",aktualneC);</span>
<a name="l02333"></a>02333 <span class="comment">//</span>
<a name="l02334"></a>02334 <span class="comment">//    //AnalizujDane();</span>
<a name="l02335"></a>02335 <span class="comment">//</span>
<a name="l02336"></a>02336 <span class="comment">//   // AlgorytmH1();</span>
<a name="l02337"></a>02337 <span class="comment">//    //WynikiZbiorcze("blabla.txt");</span>
<a name="l02338"></a>02338 <span class="comment">//    //WypiszWektory(MSK_INDEX|MSK_P|MSK_W,SORT_I);</span>
<a name="l02339"></a>02339 <span class="comment">//</span>
<a name="l02340"></a>02340 <span class="comment">//</span>
<a name="l02341"></a>02341 <span class="comment">//</span>
<a name="l02342"></a>02342 <span class="comment">//      //GLPK_R_D();</span>
<a name="l02343"></a>02343     <a class="code" href="main_8c.html#01f7419ee78625ea24a0522dbd13917c">ZwolnijPamiec</a>();
<a name="l02344"></a>02344     <span class="keywordflow">return</span> 0;
<a name="l02345"></a>02345 }
<a name="l02346"></a>02346 
</pre></div></div>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"><title>_</title></head>
<body><hr style="width: 100%; height: 2px;"><table style="text-align: left; width: 100%; height: 34px;" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td style="vertical-align: top;"><small style="font-family: Helvetica,Arial,sans-serif;"><span style="font-style: italic;">Dokumentacja pracy in&#380;ynierskiej,&nbsp;Kacper D. Tom&#380;y&#324;ski</span></small><big><br></big></td><td style="text-align: right; vertical-align: top;"><img style="width: 42px; height: 33px;" alt="" src="img/IAlogo0.gif" align="top" vspace="10"><small> &nbsp;</small><img style="width: 42px; height: 59px;" alt="" src="img/eiti.GIF"></td></tr></tbody></table><br></body></html>
